题目描述

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. 常见的几个angular.js的问题

    来源于网络收集 一.ng-show/ng-hide 与 ng-if的区别? 我们都知道ng-show/ng-hide实际上是通过display来进行隐藏和显示的.而ng-if实际上控制dom节点的增删 ...

  2. 服务器上的json类型的文件提示找不到

    搞Google地图的时候, 本地是可以显示的, 但是到了服务器上地图一直显示不出来, 火狐打开F12,发现是找不到json的文件, 本来还以为是IIS中"请求筛选"的问题,后来发现 ...

  3. 【Solr】索引库查询界面详解

    目录 索引库查询界面详解 回到顶部 索引库查询界面详解 q:主查询条件.完全支持lucene语法.还进行了扩展. fq:过滤查询.是在主查询条件查询结果的基础上进行过滤.例如:product_pric ...

  4. 懒加载的用处和赋nil操作[iOS开发教程]

    懒加载的用处和赋nil操作 1:数据,清空操作: self.array = nil; 2:归档从新从本地获取数据 self.archive = nil; ##id = nil的用处 block当参数, ...

  5. 清北暑假模拟day1 艳阳天

    /* 注意P有可能不是质数,不要用欧拉函数那一套,正解可以倍增,就是等比数列和的性质,注意n是否为奇数 */ #include <cstdio> #include <algorith ...

  6. 清北暑假模拟day2 之

    /* 现场代码,枚举每条边删除 */ #include<iostream> #include<cstdio> #include<string> #include&l ...

  7. Windows Phone 8下 友盟社会化组件SDK的使用。

    由于项目的需要,要将友盟的社会化组件SDK由0.9更新至2.0. 版本变化比较大. 1.很多类以及命名空间已经取消了. 如UmengSocialSDK.Net.Request命名空间, UmengSo ...

  8. Ruby类的创建与使用

    Ruby是一种面向对象编程语言,这意味着它操纵的编程结构称为"对象" 先上代码, 了解类的定义与使用方式 class Computer $manufacturer = " ...

  9. maven 项目配置

    创建java web的maven项目方法有两种,一是先创建maven项目,再选择jdk 和 dynamic web 运行环境 ,二是创建java项目,然后转化为maven项目 1.将普通java项目转 ...

  10. ios 第三方登录

    ios 第三方登录通常的做法是, 1.登录后,获得第三方的uid,调用服务器登录接口,如服务器返回无此用户,转2,有此用户,转3. 2.服务器返回无此用户,需完善用户资料,如果完成,则在服务器创建与第 ...