/****************************************************该题充分运用与运算的特点,成对消除,单的最后留下****************************************************/#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int main(){char str1[10], str2[10];int n;while(~scanf("%d", &n) ){getchar();gets(str1);for(int i=0; i<2*n-2; i++){gets(str2);for(int j=0; j<7; j++)str1[j] = str1[j] ^ str2[j]; //两个字符串各自与运算,可以判定最后剩下的不成对的一个}printf("%s\n", str1);}}/*DescriptionAlice bought a lot of pairs of socks yesterday. But when she went home, she found that she has lost one of them. Each sock has a name which contains exactly 7 charaters.Alice wants to know which sock she has lost. Maybe you can help her.InputThere are multiple cases. The first line containing an integer n (1 <= n <= 1000000) indicates that Alice bought n pairs of socks. For the following 2*n-1 lines, each line is a string with 7 charaters indicating the name of the socks that Alice took back.OutputThe name of the lost sock.Sample Input2aabcdefbzyxwvubzyxwvu4aqwertyeas fghaqwertyeasdfgheasdfghaqwertyaqwerty20x0abcd0ABCDEF0x0abcdSample Outputaabcdefeas fgh0ABCDEF*/
原文:http://www.cnblogs.com/sober-reflection/p/cd588e8df002561ac9f5a9bfed72c57f.html