首页 > 代码库 > zoj 3432 与运算运用
zoj 3432 与运算运用
/****************************************************
该题充分运用与运算的特点,成对消除,单的最后留下
****************************************************/
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
char str1[10], str2[10];
int n;
while(~scanf("%d", &n) )
{
getchar();
gets(str1);
for(int i=0; i<2*n-2; i++)
{
gets(str2);
for(int j=0; j<7; j++)
str1[j] = str1[j] ^ str2[j]; //两个字符串各自与运算,可以判定最后剩下的不成对的一个
}
printf("%s\n", str1);
}
}
/*
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
eas fgh
aqwerty
easdfgh
easdfgh
aqwerty
aqwerty
2
0x0abcd
0ABCDEF
0x0abcd
Sample Output
aabcdef
eas fgh
0ABCDEF
*/
来自为知笔记(Wiz)
附件列表
zoj 3432 与运算运用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。