secret message

 

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.

 

 

i   l   o   v                                        *    j    e    i  

e  y  o   y                                        *    a    y    l

j  a   c   k                                        *    c    o    o

*  *   *   *                                      *    k    y    v

 

 

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





#include<stdio.h>
#include"iostream"
#include<string.h>
#include"math.h"
using namespace std;
#define N 10005
int main()
{
char str2[N];
int i,j,k,t,f=0,s,l,m;
int n;
scanf("%d",&n);
getchar();
for(s=0;s<n;s++)
{
memset(str2,'*',10005*sizeof(char));
gets(str2);
l=strlen(str2);
m=ceil(sqrt(l));
k=m*m;
str2[l]='*';
str2[k]='\0';
for(j=k-m;j<k;j++)
{
f=j;
while(f>=0){
if(str2[f]!='*')
printf("%c",str2[f]);
f=f-m;
}

}
printf("\n");

}
return 0;
}

 

转载于:https://www.cnblogs.com/1023x/p/5576491.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值