题目描述

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. codeforces Diagrams & Tableaux1 (状压DP)

    http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...

  2. 用友android

    获取token要改 value要改 不用通配符 直接双引号

  3. 【转载】Unity 优雅地管理资源,减少占用内存,优化游戏

    转自:星辰的<Unity3D占用内存太大的解决方法> 最近网友通过网站搜索Unity3D在手机及其他平台下占用内存太大. 这里写下关于Unity3D对于内存的管理与优化. Unity3D  ...

  4. ASP FORM表单提交判断

    ASP提交表单是先进行Form填写检测,检测完成没问题之后再执行写入数据库表操作. 相关源码: <script language="javascript"> funct ...

  5. ASP.NET 生成报表的几中方案

    1. 用html 表格绘制报表,javascript导出EXCEL 2. 采用datagrid绑定报表数据,用后台方法导出 //Response.AppendHeader("Content- ...

  6. .Net程序员必须要知道的东西之HttpModules与HttpHandlers介绍

    一.ASP.NET对请求处理的过程: 当客户端请求一个*.aspx文件的时候,这个请求会被inetinfo.exe进程截获,它判断文件的后缀(aspx)之后,将这个请求转交给ASPNET_ISAPI. ...

  7. Unity手游之路<一>C#版本Protobuf

    http://blog.csdn.net/janeky/article/details/17104877 个游戏包含了各种数据,包括本地数据和与服务端通信的数据.今天我们来谈谈如何存储数据,以及客户端 ...

  8. Palindrome Partitioning II Leetcode

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  9. 移动端rem切图

    1.为什么用rem 根据屏幕大小,自动调整大小 2.如何使用rem 分以下几步 a.用ps把设置稿弄成640px或者750px的(记得等比例缩放) b.调试时记得把浏览器默认最小字体设置为最小.手机端 ...

  10. Oracle 恢复被删除的数据,解决误操作删除数据

    在删除数据的时候不小心,把delete语句执行错了,把别的表给delete,而且还执行了commit!真汗.......数据是相当的重要........废话少说了!赶快找方法吧: 第一种: 1.打开F ...