题目描述

Jack and Jill developed a special encryption method, so they can enjoy conversations without worrrying about eavesdroppers. Here is how: let L be the length of the original message, and M be the smallest square number greater than or equal to L. Add (M − L) asterisks to the message, giving a padded message with length M. Use the padded message to fill a table of size K × K, where K2= M. Fill the table in row-major order (top to bottom row, left to right column in each row). Rotate the table 90 degrees clockwise. The encrypted message comes from reading the message in row-major order from the rotated table, omitting any asterisks.

For example, given the
original message ‘iloveyouJack’, the message length is L = 12. Thus the padded
message is ‘iloveyouJack****’, with length M = 16. Below are the two tables
before and after rotation.

Then we read the secret message as
‘Jeiaylcookuv’.

输入

The first line of input is the
number of original messages, 1 ≤ N ≤ 100. The following N lines each have a
message to encrypt. Each message contains only characters a–z (lower and upper
case), and has length 1 ≤ L ≤ 10 000.

输出

For each original message,
output the secret message.

样例输入

2
iloveyoutooJill
TheContestisOver

样例输出

iteiloylloooJuv
OsoTvtnheiterseC

解题心得:
  题意是输入字符串(长度L),然后将每个字符从上到下,从左到右挨着放到一个k*k的方格里,剩余的用*补上,然后将方格顺时针旋转一下(90度),然后在按照从上到下,从左到右的顺序输出(*省略掉)。K值:先把L开方,然后向上取整再加1,然后平方,即得到K的值。
  我在做的时候忘记了把X清零,结果又是浪费了时间。。。 代码:
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath> using namespace std; int main()
{
int n;
int x=;
int size=;
double k=;
int k1=;
int s;
char a[];
char c[][];
scanf("%d",&n);
for(int i=;i<n;i++){
cin>>a;
size=strlen(a);
k=sqrt(size);
k1=ceil(k);
s=k1*k1;
if(size!=s){
int add=s-size;
for(int i1=;i1<add;i1++){
a[size+i1]='*';
}
a[size+add]='\n';
}
for(int j=;j<k1;j++){
for(int j1=;j1<k1;j1++){
c[j][j1]=a[x++];
}
}
x=; //做的时候被我落掉了,结果好久才找到错误!
for(int r=;r<k1;r++){
for(int p=k1-;p>=;p--){
if(c[p][r]!='*'){
printf("%c",c[p][r]);
}
}
}
printf("\n"); }
return ;
}

2078 Problem H Secret Message 中石油-未提交-->已提交的更多相关文章

  1. 互联网项目中mysql推荐(读已提交RC)的事务隔离级别

    [原创]互联网项目中mysql应该选什么事务隔离级别 Mysql为什么不和Oracle一样使用RC,而用RR 使用RC的原因 这个是有历史原因的,当然要从我们的主从复制开始讲起了!主从复制,是基于什么 ...

  2. 2106 Problem F Shuffling Along 中石油-未提交-->已提交

    题目描述 Most of you have played card games (and if you haven’t, why not???) in which the deck of cards ...

  3. 【动态规划】盖房子(house)--未提交--已提交

    问题 D: 盖房子(house) 时间限制: 1 Sec  内存限制: 64 MB提交: 27  解决: 16[提交][状态][讨论版] 题目描述 FJ最近得到了面积为n*m的一大块土地,他想在这块土 ...

  4. 翻译:如何向MariaDB中快速插入数据(已提交到MariaDB官方手册)

    本文为mariadb官方手册:How to Quickly Insert Data Into MariaDB的译文. 原文:https://mariadb.com/kb/en/how-to-quick ...

  5. Eclipse中使用GIT将已提交到本地的文件上传至远程仓库

    GIT将已提交到本地的文件上传至远程仓库: 1.  右击项目——Team——Push to Upstream,即可将已保存在本地的文件上传推至GIT远程仓库.

  6. Secret Message ---- (Trie树应用)

    Secret Message   总时间限制:  2000ms  内存限制:  32768kB 描述 Bessie is leading the cows in an attempt to escap ...

  7. bzoj 1590: [Usaco2008 Dec]Secret Message 秘密信息

    1590: [Usaco2008 Dec]Secret Message 秘密信息 Description     贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息.     信息是二进制的,共 ...

  8. 洛谷P2922 [USACO008DEC] 秘密消息Secret Message [Trie树]

    洛谷传送门,BZOJ传送门 秘密消息Secret Message Description     贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息.     信息是二进制的,共有M(1≤M≤5 ...

  9. 洛谷p2922[USACO08DEC]秘密消息Secret Message

    题目: 题目链接:[USACO08DEC]秘密消息Secret Message 题意: 给定n条01信息和m条01密码,对于每一条密码A,求所有信息中包含它的信息条数和被它包含的信息条数的和. 分析: ...

随机推荐

  1. DigitalOcean 建站笔记

    由于在默认的情况下digitalocean的VPS没有设置swap分区,用df -h命令查看的话,整个VPS上只有一个20G的分区.用free命令查看的话,swap分区的大小是0,增加swap分区的命 ...

  2. 自动去除nil的NSDictionary和NSArray构造方法

    http://www.jianshu.com/p/a1e8d8d579c7 极分享 http://www.finalshares.com/

  3. PHP基础OOP(一)

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. OC第四节——NSDictionary和NSMutableDictionary

    NSDictionary    1.什么是字典        字典是也是一种集合结构,功能与我们现实中的字典工具一样    2.字典的元素是什么        任意类型的对象地址构成键值对    3. ...

  5. OS X 10.10.5编译Android5.1.1源码

    --------------------------------------------------写在前面---------------------------------------------- ...

  6. Wdcp在安装memcached出现错误的解决办法

    今天在安装memcached时出现了以下错误(tar: libevent-1.4.14b-stable.tar.gz: Cannot open: No such file or directory), ...

  7. windows 下wamp环境1 配置之apache的安装

    一.安装apache2.4 打开网站 apachelounge.com    https://www.apachelounge.com/ 点击左侧Downloads,然后选择对应的版本,这里选择Apa ...

  8. ASP.NET发送邮件(QQ发送)

    public void SetEmail()        {            //电子邮件对象            MailMessage mailMessage = new MailMes ...

  9. Unity3d用户手册用户指南 电影纹理(Movie Texture)

    http://www.58player.com/blog-2327-952.html 电影纹理(Movie Texture) 注意:这只是专业/高级功能.   桌面 电影纹理是从视频文件创建的动画纹理 ...

  10. ios10 UNNtificationRequest UNUserNotificationCenter的应用 推送之本地推送

    iOS10 已经 "deprected" 我们的UILocalNotification 采用了全新的UNUserNotificationCenter; 1 首先,你需要引进< ...