题目链接:Problem - C - Codeforces
解题思路:
用map存字母和出现的次数,然后遍历三个字母数组,如果map值为1,则加三分,为2加1分,否则不加分。
下面是c++代码:
#include<iostream>
#include<map>
using namespace std;
int main()
{int n, num, a1 = 0, a2 = 0, a3 = 0;cin >> n;while (n != 0) {a1 = 0, a2 = 0, a3 = 0;map<string, int> mp;cin >> num;string* arr1 = new string[num];string* arr2 = new string[num];string* arr3 = new string[num];for (int i = 0; i < num; i++) {cin >> arr1[i];mp[arr1[i]]++;}for (int i = 0; i < num; i++) {cin >> arr2[i];mp[arr2[i]]++;}for (int i = 0; i < num; i++) {cin >> arr3[i];mp[arr3[i]]++;}for (int i = 0; i < num; i++) {if (mp[arr1[i]] == 1) {a1 += 3;}else if (mp[arr1[i]] == 2) {a1 += 1;}}for (int i = 0; i < num; i++) {if (mp[arr2[i]] == 1) {a2 += 3;}else if (mp[arr2[i]] == 2) {a2 += 1;}}for (int i = 0; i < num; i++) {if (mp[arr3[i]] == 1) {a3 += 3;}else if (mp[arr3[i]] == 2) {a3 += 1;}}cout << a1 << " " << a2 << " " << a3 << endl;n--;}return 0;
}