zoj 3432 Find the Lost Sock(字符串异或位运算)
很郁闷啊,太笨了。。。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
#ifndef ONLINE_JUDGE
freopen("indata.txt", "r", stdin);
#endif
int n;
while(scanf("%d", &n) != EOF)
{
getchar();
char ans[10], inStr[10];
gets(ans);
// scanf("%[^\n]", ans);
n = (n << 1) - 2;
while(n--)
{
gets(inStr);
// getchar();
// scanf("%[^\n]", inStr);
for(int i = 0; i < 7; i++)
{
ans[i] ^= inStr[i];
}
}
printf("%s\n", ans);
}
return 0;
}
///////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long LL;
int main()
{
#ifndef ONLINE_JUDGE
freopen("indata.txt", "r", stdin);
#endif
int n;
char str[10];
while(scanf("%d", &n) != EOF)
{
getchar();
LL hashInt = 0;
int i, j;
n = (n << 1) - 1;
for(i = 0; i < n; i++)
{
gets(str);
LL t = 0;
for(j = 0; j < 7; j++)
{
t = t * 256 + str[j];
}
hashInt ^= t;
}
for(j = 6; j >= 0; j--)
{
str[j] = hashInt % 256;
hashInt /= 256;
}
printf("%s\n", str);
}
return 0;
}
浙公网安备 33010602011771号