游戏开发论坛

 找回密码
 立即注册
搜索
查看: 915|回复: 0

密码转换wxh zt

[复制链接]

1367

主题

1993

帖子

2118

积分

金牌会员

Rank: 6Rank: 6

积分
2118
发表于 2005-7-19 14:07:00 | 显示全部楼层 |阅读模式
Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number of columns and write the message (letters only) down the columns, padding with extra random letters so as to make a rectangular array of letters. For example, if the message is “There’s no place like home on a snowy night” and there are five columns, Mo would write down



t o i o y
h p k n n
e l e a i
r a h s g
e c o n h
s e m o t
n l e w x




Note that Mo includes only letters and writes them all in lower case. In this example, Mo used the character ‘x’ to pad the message out to make a rectangle, although he could have used any letter.



Mo then sends the message to Larry by writing the letters in each row, alternating left-to-right and right-to-left. So, the above would be encrypted as



toioynnkpheleaigshareconhtomesnlewx



Your job is to recover for Larry the original message (along with any extra padding letters) from the encrypted one.



Input



There will be multiple input sets. Input for each set will consist of two lines. The first line will contain an integer in the range 2. . . 20 indicating the number of columns used. The next line is a string of up to 200 lower case letters. The last input set is followed by a line containing a single 0, indicating end of input.



Output



Each input set should generate one line of output, giving the original plaintext message, with no spaces.



SampleInput



5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0




SampleOutput



theresnoplacelikehomeonasnowynightx
thisistheeasyoneab



把输入的字符串看成二维数组,再得到每个字符的编号,输出。



s[i+j*n];



s[(n-i-1)+j*n];




*/



#include <iostream>
using namespace std;
int main()
{
int n;
while(cin>>n&&n)
{
  string s;
  cin>>s;
  
  for(int i=0;i<n;i++)
   {
    int m=0;
   for(int j=0;j<s.length()/n;j++)
  {
   if(m%2==0)
   cout<<s[i+j*n];
   else
    cout<<s[(n-i-1)+j*n];
   m++;
  }
  }
   cout<<endl;
}
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-26 11:52

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表