编程学习--刷题

这是一个关于三人玩WordGame的点数计算问题。每个人写下三个不同的3个字母的单词,然后根据规则计算每个人的得分:独自写的得3分,两人共有的得1分,三人都有的不得分。程序读取输入,处理多个测试用例,并输出每个人的得分。
摘要由CSDN通过智能技术生成

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<<" ";
        }
    }
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值