Problem G: Find The Difference
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 214 Solved: 161
[ Submit][ Status][ Web Board]
Description
Diao Fei is very good at the game which names “Find the difference”. The game’s rule is giving two pictures and you should find all the differences between these two pictures.
Diao Ze is very good at math, and he thinks finding the differences in pictures is very boring, he giving a similar problem to Diao Fei: Giving you two number sequences, can you find the differences between these two number sequences?
To simplify the problem, the two number sequences satisfied:
·In each sequence, all the numbers are distinct.
·The first sequence has exactly one more number than the second sequence and there is only one number which is in the first sequence but not in the second sequence.
Your task is to help Diao Fei find the number which is in the first sequence but not in the second sequence.
Input
The first line contains an integer T, indicating the total number of test cases.
For each test case, there are three lines. The first line contains an integer n(), indicating the first sequence has numbers and the second sequences has n-1 numbers. Then the second line contains n integers which in the first sequence and the third line contains n-1 integers which in the second sequence. Each integer in each sequence is less than 231.
Output
For each test case, output the answer in one line.
Sample Input
231 2 31 2534 421 97 456 19238421 19238 97 34
Sample Output
3456
HINT
#include<stdio.h>
#include<string.h>
int inf=9999999;
int main()
{
int a[100005];
int b[100005];
int T,i,j;
scanf("%d",&T);
while(T--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
int n;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<n;i++)
scanf("%d",&b[i]);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-1;j++)
{
if(a[i]==b[j])
break;;
}
if(j==n)
{
printf("%d\n",a[i]);
break;
}
}
}
return 0;
}