Word Game
Three guys play a game: first, each person writes down �n distinct words of length 33. Then, they total up the number of points as follows:
if a word was written by one person — that person gets 3 points,
if a word was written by two people — each of the two gets 1 point,
if a word was written by all — nobody gets any points.
In the end, how many points does each player have?
Input
The input consists of multiple test cases. The first line contains an integer �t (1≤�≤1001≤t≤100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer �n (1≤�≤10001≤n≤1000) — the number of words written by each person.
The following three lines each contain �n distinct strings — the words written by each person. Each string consists of 33 lowercase English characters.
Output
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the �i-th integer should be the number of points earned by the �i-th guy.
Sample 1
Inputcopy | Outputcopy |
3 1 abc def abc 3 orz for qaq qaq orz for cod for ces 5 iat roc hem ica lly bac ter iol ogi sts bac roc lly iol iat | 1 3 1 2 2 6 9 11 5 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
map<string , int> mp;
string a[4][1010];
int n;
cin>>n;
for(int i = 1 ; i <= 3 ; i++ )
{
for(int j = 1 ; j <= n ; j++ )
{
cin>>a[i][j];
mp[a[i][j]]++;
}
}
for(int i = 1 ; i <= 3 ; i++)
{
int cnt = 0;
for(int j = 1 ; j <= n ; j++)
{
if(mp[a[i][j] ] == 1)cnt+=3;
else if(mp[a[i][j]] == 2)cnt+=1;
}
cout<<cnt<<" ";
}
}
}