3812: Find the Lost Sock

3812: Find the Lost Sock分享至QQ空间

时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte
总提交:354           测试通过:144

描述

Alice 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.

输入

There 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.

输出

The name of the lost sock.

样例输入

2aabcdefbzyxwvubzyxwvu4aqwertyeas fghaqwertyeasdfgheasdfghaqwertyaqwerty20x0abcd0ABCDEF0x0abcd

样例输出

aabcdefeas fgh0ABCDEF

提示

Because of HUGE input, scanf is recommended.

题目来源


/*首先这题的数据量太大,自己用了map去存结果超时,自己后来在网上百度了一下发现可以用亦或去处理,A^B^A = A^(B^A) = A^A^B = B,因此把输入的所有字符串都亦或就可以得到结果*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    int n;
    char s[8];
    int cmp[8]={0};
    while(scanf("%d",&n)!=EOF)
    {
        getchar();
        for(int i=0;i<7;i++)
            cmp[i]=0;
        for(int i=0;i<2*n-1;i++)
        {
            gets(s);
            for(int j=0;j<7;j++)
            {
                cmp[j]=cmp[j]^s[j];
            }
        }
        for(int i=0;i<7;i++)
            printf("%c",cmp[i]);
        putchar('\n');
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_40605429/article/details/80564073
今日推荐