Title 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
代码如下:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int s[1011];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0; i<n; i++)
{
scanf("%d",&s[i]);
}
int k = 'A',j=0;
///先求出来这个大写字母
for(j=0; j<=26; j++)
{
int t,flag = 0;
for( t=0; t<n; t++)
{
int l = s[t]^k;
if(!(l>='A' && l<='Z'))
break;
}
if(t == n)
break;
k = k+1;
}
// printf("%d\n",k);
for(int i=0; i<n; i++)
{
printf("%c",s[i]^k);
}
printf("\n");
}
return 0;
}