[UVA] 11222 - Only I did it!
D. Only I did it!
Time limit: 1s
Once upon a time, in the land of Ceeplenty, lived 3 friends that liked to solve problems. They used internet engines to look for problems and they often tried to solve the problems that none of the other 2 had solved. They once met you and you managed to convince them that you were better at problem solving. So they asked you to write a program that tells which of the 3 friends solved more problems that none of the other 2 have solved.
Input
The first line of input gives the number of cases, (). test cases follow. Each test case is composed of three lines corresponding to the problems solved by the first, second and third friend, respectively. Each of these lines has an integer () followed by the list of solved problems. A solved problem is identified uniquely by a positive integer smaller or equal than .
Output
The output is comprised a line identifying the test case with the string Case #C: (where C is the number of the current test case). Then print another line with the number of the friend (1, 2 or 3) asked in the description followed by the number of problems that he solved but none of the other 2 did, followed by the sorted list of these problems in one line. When there is a tie, print one such line for each tied friend, sorted by the number of the friend.
Sample input
4 3 1 2 3 4 4 5 6 7 5 8 9 10 11 12 2 1 5 2 2 3 3 2 3 1 6 400 401 402 403 404 405 2 101 100 7 400 401 402 403 404 405 406 1 1 1 2 1 3
Sample output
Case #1: 3 5 8 9 10 11 12 Case #2: 1 1 5 Case #3: 2 2 100 101 Case #4: 1 1 1 2 1 2 3 1 3
#include <stdio.h>
#include <algorithm>
using namespace std;
int main() {
int t, Case = 0;
int i, j;
scanf("%d", &t);
while(t--) {
printf("Case #%d:\n", ++Case);
int A[3], B[3][1000];
int mark[10001] = {};
for(i = 0; i < 3; i++) {
scanf("%d", &A[i]);
for(j = 0; j < A[i]; j++) {
scanf("%d", &B[i][j]);
mark[B[i][j]]++;
}
sort(B[i], B[i]+A[i]);
}
int max = 0, solve[3];
for(i = 0; i < 3; i++) {
int tmp = 0;
for(j = 0; j < A[i]; j++)
if(mark[B[i][j]] == 1)
tmp++;
if(tmp > max)
max = tmp;
solve[i] = tmp;
}
for(i = 0; i < 3; i++) {
if(solve[i] == max) {
printf("%d %d", i+1, solve[i]);
for(j = 0; j < A[i]; j++)
if(mark[B[i][j]] == 1)
printf(" %d", B[i][j]);
puts("");
}
}
}
return 0;
}