Alice bought a lot of pairs of socks yesterday. But when she was went home, she found that she had lost one of the them. Each sock has a name which contains exactly 7 charaters.
Alice wants to know which sock she had lost. Maybe can help her.
Input
There is multiple cases. The first line containing a integer n (1 <= n <= 1000000) indicates that Alice bought N Pairs of socks. For the following to1 lines, each line was a string with 7 charaters indicating the name of the socks that Alice Took back.
Output
The name of the lost sock.
Sample Input
2aabcdefbzyxwvubzyxwvu4aqwertyeas FGHAQWERTYEASDFGHEASDFGHAQWERTYAQWERTY20X0ABCD0ABCDEF0X0ABCD
Sample Output
Aabcdefeas Fgh0abcdef
Hint
Because of HUGE input, scanf is recommended.
Method 1:
#include <cstdio> #include <cmath> #include <cstring> #include <stdlib.h>char a[2000005][8];// Note: If you use Qsort to sort a two-dimensional array , you should use strcmp if it is not-int cmp (const void *a,const void *b) { return strcmp ((char*) A, (char*) b);} int main () { int i,j,k; int n; Fast row, detects adjacent strings while (scanf ("%d", &n)!=-1) { getchar (); for (i=0;i<2*n-1;i++) gets (A[i]); Qsort (A,2*n-1,sizeof (a[0]), CMP); if (strcmp (a[0],a[1])!=0) {printf ("%s\n", a[0]); continue;} for (i=0;i<2*n-1;i+=2) if (strcmp (a[i],a[i+1])!=0) {printf ("%s\n", A[i]);
Method 2: Each string is 7 characters, counting each character of each string with an array if the last character has an odd number of characters, the character is output (get)
Winter D3 A Find the Lost Sock