破译密码
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2801 Accepted Submission(s): 1270
Problem Description
有个叫“猪头帮”的国家,采用一种简单的文法加密,他们所用的语言里面只有大写字母,没有其他任何字符;现在还知道他们加密的方法是:只用一个大写字母和原文进行异或运算生成密文。请你帮忙解开。
Input
有若干组,每组输入有2行,第一行整数N表示有N个密文,接着一行有N个整数分别表示N个密文。
Output
输出仅有大写字母组成的原文。
Sample Input
30 17 6 9 8 3 0 1 6 7 4 5 10 11 8 9 14 15 12 13 18 19 16 17 22 23 20 21 26 27 24
Sample Output
SDKJABCDEFGHIJKLMNOPQRSTUVWXYZ
Author
SmallBeer(CML)
Source
Recommend
lcy
解题思路:X = 12 ^ ' A ' ,则‘ A ’ = 12 ^ X。因没给出解密的大写字母,本题需要用各个大写字母逐个套用,直到解密得到所有字母皆为大写字母为止!
#include<stdio.h> int main() { int c; int t; char x; int a[100000]; int i,j; char b[100000]; while(scanf("%d",&t)!=EOF) { for(i=0;i<t;i++) scanf("%d",&a[i]); for(i=0;i<26;i++) //逐个字母套用,直到解密后所有字符全部为大写字母为止! { c=i+'A'; for(j=0;j<t;j++) { b[j]=a[j]^c; if(b[j]<'A'||b[j]>'Z') break; } if(j==t) break; } for(i=0;i<t;i++) printf("%c",b[i]); printf("\n"); } return 0; }
转载于:https://blog.51cto.com/huahua520amy/1373710