首页 > 学院 > 开发设计 > 正文

ZCMU-1416-Find the Lost Sock

2019-11-11 01:19:40
字体:
来源:转载
供稿:网友

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 indicating the name of the socks that Alice took back.

Output

The name of the lost sock.

Sample Input

2aabcdefbzyxwvubzyxwvu4aqwertyeasafghaqwertyeasdfgheasdfghaqwertyaqwerty20x0abcd0ABCDEF0x0abcd

Sample Output

aabcdefeasafgh0ABCDEF【解析】这道题我一直没做出来..现在问了一下才知道了做法...果然自己太笨.言归正传其实这道题的意思就是给你袜子的名字,看哪个名字出现的次数是奇数次就是丢失的袜子,输出这个名字就可以了。其实就是统计那个字符出现了奇数次,出现奇数次的字符我们就要输出。因为袜子总是成双存在的。
#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;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表