ZOJ 3432 Find the Lost Sock (水题)

题目

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3432

题意

给2n-1个字符串,其中有n对相同的字符串,求剩下的那个字符串

解法

根据异或的性质,用第一个串与后面每一个串按位异或,即为所得

代码

#include <cstdio>
int main() {
    int n;
    char a[10], b[10];
    while(~scanf("%d\n", &n)) {
        gets(a);
        for(int i = 0; i < n * 2 - 2; i++) {
            gets(b);
            for(int j = 0; j < 7; j++)
                a[j] ^= b[j];
        }
        printf("%s\n", a);
    }
    return 0;
}

Source

ZOJ Monthly, November 2010

posted @ 2015-08-24 00:49  ACM_Record  阅读(124)  评论(0编辑  收藏  举报