您的位置:首页 > 其它

ZCMU-1416-Find the Lost Sock

2017-02-07 22:46 281 查看

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: