信息战(一)—想法

信息战(一)——加密程序

1000ms
65536KB
 
64-bit integer IO format: %lld      Java class name: Main
 
在战争时期,各个国家都要保证军队的行动保密性,所以在信息传达时会采取各种加密方法。有一天,A国安全局成员Oo(也就是传说中的ZSL),
发明了一种对指令的加密方法。具体操作如下,取两个正整数X、Y,对于一段明文字符串,将其按行填入一个X行Y列的矩阵中(非字母不填、而且
所有字母要求权转换为大写),若未填满,则按字母表顺序顺次填充(’A’…’Z’循环填充)。比如对于X=3,Y=3,明文为”Problem”时,矩阵填充后
的结果为:
PRO
BLE
MAB
这样,Oo就得到了一个矩阵,将他按列输出就得到了Oo所要的的密文“PBMRLAOEB”。由于A国编程人员奇缺。所以Oo向你求助,希望你能够帮助
他写一个加密程序,从而使得对于任意给定的X、Y以及明文,程序都能输出正确的密文。

Input

第一行X,Y(0 < X <= 200,0 < Y <= 200)。
第二行至末尾每行均为一个明文(保证明文中字母的个数N <= X*Y)。
 

Output

对于每一行明文输出对应的一行密文。
 

Sample Input

3 3
Problem
t e s t
l I 156-*/- S t
u 45/-90 N I v \908() 8768 *er #!@$& S a L
 

Sample Output

PBMRLAOEB
TTCEADSBE
LTCIADSBE
UVSNEAIRL
 

Source

第七届北京师范大学程序设计竞赛热身赛第二场

Author

51isoft

Tags ( Click to see )

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<queue>
 4 #include<stdio.h>
 5 #include<stdlib.h>
 6 #include<string.h>
 7 #include<math.h>
 8 #include <ctype.h>
 9 using namespace std;
10 #define sr(x) scanf("%d",&x);
11 #define sc(x) printf("%d",x);
12 #define hh printf("\n");
13 
14 
15 int main()
16 {
17     int x,y,g=0,i,j;
18     sr(x);sr(y);
19     char a[40001],s;
20     getchar();
21     while((s=getchar())!=EOF)
22     {
23         if(isalpha(s))a[g++]=toupper(s);
24         else if(s=='\n')
25         {
26             for(i=g;i<x*y;i++)a[i]=(i-g)%26+'A';
27             for(i=0;i<y;i++)for(j=0;j<x;j++)printf("%c",a[i+j*y]);
28             hh;
29             g=0;
30             memset(a,0,sizeof(a));
31         }
32     }
33     return 0;
34 }

 

posted on 2013-11-07 23:57  lveternal  阅读(211)  评论(0编辑  收藏  举报

导航