POJ 2039 && HDU 1200 To and Fro(水~)

原创 2015年08月26日 16:27:39

Description
给出2<=N<=20和加密过的字符串(长度<=200),输出解密后的字符串。
加密规则:例如theresnoplacelikehomeonasnowynightx,按列写出,共N列
  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
再按照奇数行,左至右,偶数行,右到左的顺序按行写出即可
Input
多组用例,每组用例第一行为字符串每行字符数n,第二行为字符串,以n=0结束输入
Output
对于每组用例,按题意描述输出
Sample Input
5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0
Sample Output
theresnoplacelikehomeonasnowynightx
thisistheeasyoneab
Solution
简单字符串处理
Code

#include<stdio.h>
#include<string.h>
int main()
{
    int n;
    char map[250][250];
    while(scanf("%d",&n),n)
    {
        getchar();
        char c[250];
        gets(c);
        int len=strlen(c);
        int m=len/n;
        int k=0;
        for(int i=0;i<m;i++)
        {
            if(i%2==0)
                for(int j=0;j<n;j++)
                    map[i][j]=c[k++];
            else if(i%2)
                for(int j=n-1;j>=0;j--)
                    map[i][j]=c[k++];
        }
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                printf("%c",map[j][i]);
        printf("\n");
    }
    return 0;
} 
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

POJ 2039:To and Fro

To and Fro Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8632   Acc...

POJ 2039 To and Fro(我的水题之路——解密,N个字符的正逆序)

To and Fro Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7357   Acc...

【poj2039】To and Fro

【poj2039】To and Fro Description Mo and Larry have devised a way of encrypting messages. They f...

POJ2039--To and Fro--字符串水题

Description Mo and Larry have devised a way of encrypting messages. They first decide secretly on t...
  • a305657
  • a305657
  • 2013年02月22日 20:01
  • 424

poj 2039 To and Fro

To and Fro Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8460   Acc...

hdu 1200 To and Fro

To and Fro Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot...

HDOJ/HDU 1200 To and Fro(加密解密字符串)

Problem Description Mo and Larry have devised a way of encrypting messages. They first decide secre...

HDU-1200-To and Fro(Java农夫山泉+简单模拟)

To and Fro Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot...

HDU 1200 To and Fro

To and Fro Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot...

HDU1200:To and Fro

Problem Description Mo and Larry have devised a way of encrypting messages. They first decide secre...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:POJ 2039 && HDU 1200 To and Fro(水~)
举报原因:
原因补充:

(最多只允许输入30个字)