ZOJ 3432 Find the Lost Sock
来源:互联网 发布:mac mail qq企业邮箱 编辑:程序博客网 时间:2024/04/29 16:22
[Submit]
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 helpher.
Input
There are multiple cases. The first line containing an integern (1 <= n <=1000000) indicates that Alice bought n pairs of socks. Forthe following 2*n-1 lines, each line is a string with 7charaters indicating the name of the socks that Alice tookback.
Output
The name of the lost sock.
Sample Input
2aabcdefbzyxwvubzyxwvu4aqwertyeas fghaqwertyeasdfgheasdfghaqwertyaqwerty20x0abcd0ABCDEF0x0abcd
Sample Output
aabcdefeas fgh0ABCDEF
Hint
Because of HUGE input, scanf is recommended.
这题一般的解法基本都会超时的,所以不要想暴力解决,刚开学的时候学了个异或运算,没想到竟然也能用上了,呵呵(袜子真的挺好看的!)
代码:
#include<stdio.h>
#include<string.h>
int num[8];
char s[8];
int main()
{
int n,i,k;
while(scanf("%d",&n)!=EOF)
{
getchar();
memset(num,0,sizeof(num));
k=0;
n=n*2-2;
gets(s);
for(i=0;i<7;i++)
{
k=s[i];
num[i]=k;
}
while(n--)
{
gets(s);
for(i=0;i<7;i++)
{
k=s[i];
num[i]=num[i]^k;
}
}
for(k=0;k<7;k++)
printf("%c",num[k]);
printf("\n");
}
return 0;
}
- ZOJ 3432 Find the Lost Sock
- HDOJ 1597 find the nth digit
- POJ 2945 Find the Clones
-  
-
- ZOJ 1056 The Worm Turns
- ZOJ 1074 To the Max
- zoj 1006 Do the Untwist
- poj 1426 Find The Multiple
- HDOJ 1709 The Balance
- HDOJ 1010 Tempter of the Bone
- POJ 2182 Lost Cows
- poj 2182 Lost Cows 线段树
- POJ 3185 The Water Bowls
- POJ 1050 To the Max
- HDU 1405 The Last Practice
- dp 3267 The Cow Lexicon
- ZOJ 1053 FDNY to the Rescue
- ZZULI_SummerPractice(4) POJ 2312…
- ZOJ 2851 Code Formatter
- 批处理扫盲篇
- 基于HTML5和Tomcat WebSocketServlet的聊天室简单实现
- UVA 10189 C - MINES p
- ZOJ 3432 Find the Lost Sock
- HDU 动态规划(46道题目)倾情奉献
- HDU 2577 How to Type (DP)
- 背包九讲
- POj 1159 Palindrome (dp)
- ZZULI_SummerPractice(5) ZOJ 185…
- ZZULI_SummerPractice(5) ZOJ 194…
- 卡通渲染效果shard-1
- ZOJ 分类(转)写的真的很好,以后…