ZCMU-1416-Find the Lost Sock

来源:互联网 发布:淘宝子账号认证失败 编辑:程序博客网 时间:2024/05/21 16:23

1416: Find the Lost Sock

Time Limit: 2 Sec  Memory Limit: 128 MB
Submit: 311  Solved: 65
[Submit][Status][Web Board]

Description

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.

Input

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.

Output

The name of the lost sock.

Sample Input

2
aabcdef
bzyxwvu
bzyxwvu
4
aqwerty
easafgh
aqwerty
easdfgh
easdfgh
aqwerty
aqwerty
2
0x0abcd
0ABCDEF
0x0abcd

Sample Output

aabcdef
easafgh
0ABCDEF
【解析】
这道题我一直没做出来..现在问了一下才知道了做法...果然自己太笨.言归正传其实这道题的意思就是给你袜子的名字,看哪个名字出现的次数是奇数次就是丢失的袜子,输出这个名字就可以了。其实就是统计那个字符出现了奇数次,出现奇数次的字符我们就要输出。因为袜子总是成双存在的。
#include<iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[8][156];int main(){    int n,i,j;    char s[8];    while(~scanf("%d",&n))    {        memset(a,0,sizeof(a));        for(i=0;i<(2*n)-1;i++)        {            scanf("%s",s);            for(j=0;j<7;j++)            {                a[j][s[j]]++;//j代表第几位,a[i][j]表示的是第几位的字符出现次数            }        }        for(i=0;i<7;i++)        {            for(j=0;j<156;j++)            {                if(a[i][j]%2==1)//遍历输出就可以了                {                    printf("%c",j);                   break;                }            }        }        printf("\n");    }    return 0;}

0 0
原创粉丝点击