Problem - C - Codeforces
codeforces.com
map
- 제목
Word Game
- 조건
time limit per test : 1 second
memory limit per test : 256 megabytes
input : standard input
output : standard output
- 문제
Three guys play a game: first, each person writes down n distinct words of length 3. 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?
- 입력
The input consists of multiple test cases. The first line contains an integer t (1≤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≤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 3 lowercase English characters.
- 출력
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.
예제 입력1 | 예제 출력1 |
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 <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
#define endl '\n'
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string word;
int tc, sz;
cin >> tc;
while(tc--){
int cnt[3];
for(int n = 0 ; n < 3 ; n++) cnt[n] = 0;
vector<string> word_arr[3];
map<string, int> dict;
cin >> sz;
for(int n = 0 ; n < 3 ; n++){
for(int m = 0 ; m < sz ; m++){
cin >> word;
word_arr[n].push_back(word);
if(dict.find(word) == dict.end()) dict.insert(make_pair(word, 1));
else dict[word]++;
}
}
for(int n = 0 ; n < 3 ; n++){
for(int m = 0 ; m < sz ; m++){
switch(dict[word_arr[n][m]]){
case 1:{
cnt[n] += 3;
break;
}
case 2:{
cnt[n] += 1;
break;
}
}
}
}
for(int n = 0 ; n < 3 ; n++) cout << cnt[n] << ' ';
cout << endl;
}
return 0;
}