[恢]hdu 1287

2011-12-27 15:16:26

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1287

题意:这题的题意很让人莫名。其实是说存在一个大写字母x,然后让原文(都是大写字母)和x做xor后得到密文。现在给密文求原文。

因为x不知道,所以枚举x。判断方法是判断是否解密出来的原文都在'A'-'Z'范围内。

代码:

# include <stdio.h>


int num[10010] ;
int n ;

int test (int x)
{
int i ;
for (i = 0 ; i < n ; i++)
if ((num[i]^x) < 65 || (num[i]^x) >= (65+26)) return 0 ;
return 1 ;
}


int main ()
{
int i, j ;
while (~scanf ("%d", &n))
{
for (i = 0 ; i < n ;i++)
scanf ("%d", num+i) ;
for (i = 65 ; i < 65+26 ; i++)
if (test(i)) break ;
for (j = 0 ; j < n ; j++)
putchar (num[j] ^ i) ;
printf ("\n") ;
}
return 0 ;
}



原文地址:https://www.cnblogs.com/lzsz1212/p/2315389.html