ZCMU-1416-Find the Lost Sock
2017-02-07 22:46
281 查看
1416: Find the Lost Sock
Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 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 indicatingthe name of the socks that Alice took back.
Output
The name of the lost sock.Sample Input
2aabcdef
bzyxwvu
bzyxwvu
4
aqwerty
easafgh
aqwerty
easdfgh
easdfgh
aqwerty
aqwerty
2
0x0abcd
0ABCDEF
0x0abcd
Sample Output
aabcdefeasafgh
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; }
相关文章推荐
- 1416: Find the Lost Sock
- zoj3432 Find the Lost Sock 亦或的运用
- ZOJ 3432 Find the Lost Sock
- zoj 3432 Find the Lost Sock(解决时间超时问题)
- ZOJ 3432 Find the Lost Sock 解题报告
- zoj 3432 Find the Lost Sock
- ZOJ 3432 Find the Lost Sock
- ZOJ 3432 Find the Lost Sock
- ZOJ 3432 Find the Lost Sock(模拟)
- zoj 3432 Find the Lost Sock(zoj月赛,受打击了 = =)
- ZOJ 3432 Find the Lost Sock (异或的运用)
- zoj 3432 Find the Lost Sock
- ZOJ3432 Find the Lost Sock(异或运算)
- zoj3432——Find the Lost Sock
- ZOJ3432 Find the Lost Sock,异或运算
- 异或解题:Find the Lost Sock
- poj 1416 Find The Multiple 同余模定理
- HDU 2227 Find the nondecreasing subsequences
- HDU 1599 find the mincost route
- POJ 1426 Find The Multiple (搜索)