Who will be punished

Who will be punished 

Problem Description

This time,suddenly,teacher Li wants to find out who have missed interesting DP lesson to have fun.The students who are found out will get strictly punishment.Because,teacher Li wants all the students master the DP algorithm.
However,Li doesn't want to waste the class time to call over the names of students.So he let the students to write down their names in one paper.To his satisfaction,this time, only one student has not come.
He can get the name who has not come to class,but,it is troublesome,and,teacher always have many things to think about,so,teacher Li wants you, who is in the ACM team, to pick out the name.

Input

The first line of each case have one positive integer N.N is the number of the students,and N will not greater than 500,000.
Then,following N lines,each line contains one name of students who have attended class.The N-1 lines are presented after N lines.These N-1 lines indicates the names of students who have come to class this time,one name in one line.
The length of student's name is not greater than 30.

Output

output the name of the student who have not come to class.

Sample Input

3
A
B
C
B
C

Sample Output

A

解释:

找到只出现过一次的人的名字,而其他人都出现了两次。那么用一个字符串去异或,异或。毕竟东一个名字的,出现两次,那么两次的相同位置的字符肯定是一样。

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5 void fun(int n);
 6     int n;
 7     while(scanf("%d",&n)!=EOF)
 8     fun (n);
 9     return 0;
10 }
11 void fun (int n)
12 {  int j,i,a;
13  char str1[31],str2[31];
14    n=n*2;
15         for(i=0;i<31;i++)
16             str2[i]=0;        
17         for(i=0;i<n;i++)
18         {
19             gets(str1);
20             a=strlen(str1);
21             for(j=0;j<a;j++)
22             str2[j]=str1[j]^str2[j];
23         }
24         puts(str2);    
25 }
View Code
原文地址:https://www.cnblogs.com/gznb/p/11213688.html