题目描述

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. 降维PCA技术

    降维技术使得数据变得更易使用,并且它们往往能够去除数据中的噪声,使得机器学习任务往往更加精确. 降维往往作为预处理步骤,在数据应用到其它算法之前清洗数据.有很多技术可以用于数据降维,在这些技术中,独立 ...

  2. pygal and matplotlib(again)

    之前项目有用过pygal做chart图, 写代码很容易,几行代码就很做出一个看上去还不错的chart, 缺点是: 要调的再美观很难, Web上的交互效果较差. 在web上做可视化还是推荐采用Echar ...

  3. 国内SEO如何过滤掉不良网络信息

    对于站长们来说,首要任务就是和搜索引擎战斗,面对搜索引擎算法的不断更新,站长们也更加头疼.站长们都觉得,搜索引擎才是网站优化的"统治者",和谷歌优化相比,中国的SEO优化要复杂的多 ...

  4. php防注入

    引发 SQL 注入攻击的主要原因,是因为以下两点原因: 1. php 配置文件 php.ini 中的 magic_quotes_gpc选项没有打开,被置为 off 2. 开发者没有对数据类型进行检查和 ...

  5. AlwaysOn可用性组测试环境安装与配置(二)--AlwaysOn配置(界面与T-SQL)

    四.AlwaysOn配置 1.开启AlwaysOn高可用性功能. 1.1.开启Server01的可用性组 1.2.需要重启服务:属于SQL server群集节点的服务,需要通过故障转移界面重启 1.3 ...

  6. PHP团队 编码规范 & 代码样式风格规范

    一.基本约定 1.源文件 (1).纯PHP代码源文件只使用 <?php 标签,省略关闭标签 ?> : (2).源文件中PHP代码的编码格式必须是无BOM的UTF-8格式: (3).使用 U ...

  7. Android 实现简单音乐播放器(一)

    今天掐指一算,学习Android长达近两个月了,今天开始,对过去一段时间的学习收获以及遇到的疑难杂症做一些总结. 简单音乐播放器是我自己完成的第一个功能较为完整的APP,可以说是我的Android学习 ...

  8. netbeans tomcat

    http://www.cnblogs.com/fengzy/archive/2013/05/18/3086371.html http://blog.csdn.net/xumengxing/articl ...

  9. ThinkPHP框架表单验证

    对注册到test表的表单进行验证 在注册之前要对表单进行验证: 用户名非空验证,两次输入密码必须一致即相等验证,年龄在18~50之间即范围验证,邮箱格式正则验证. 自动验证是ThinkPHP模型层提供 ...

  10. iOS 不规则的ImageView

    http://blog.csdn.net/kevinpake/article/details/41205715 我们在做iOS开发的时候,往往需要实现不规则形状的头像,如: 那如何去实现? 通常图片都 ...