2023 年上海市大学生程序设计竞赛 - 一月赛A. It takes two

lbromine wanted to play It Takes Two, but it takes two. So he went to his friends and asked them if they had played It Takes Two.

It is known that lbromine has n friends. When he asks a friend, the friend will only answer that he has not played or played It Takes Two with another person.Because some of his friends are forgetful,maybe some friends have played It Takes Two but say no.

lbromine thinks that a friend has played It Takes Two only when the friend said he had played with another person or another friend oflbrominesaid he had played with him.

Now lbromine wants to count how many friends he thinks have never played It Takes Two so that he can choose the right person to play with.

输入格式

An integer n in the first line indicates that lbromine has n (1≤n≤105) friends.

The next n line has two strings per line. The first string represents the friend’s name, and the second string represents the answer of the friend.

It is guaranteed that the answer of lbromine's friends can only be No or a person’s name (may not be a friend of lbromine).

A person’s name only contains uppercase and lowercase letters and underscores,and the length cannot exceed 10 characters.

no one names No.

输出格式

One integer indicates how many friendslbrominethinks have never played It Takes Two

样例

input

3
CN_Amuzi No
komorebi MaverickFW
MaverickFW No

output

1
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
using namespace std;
struct Person
{
    string one, two;
};

int main()
{
    int n;
    cin >> n;
    vector<Person> people(n);
    set<string> mySet;
    string str1, str2;
    for (int i = 0; i < n; i++)
    {
        cin >> str1 >> str2;
        people[i].one = str1;
        people[i].two = str2;
        if (str2 != "No")
        {
            mySet.insert(str1);
            mySet.insert(str2);
        }
    }
    int sum = 0;
    for (int i = 0; i < n; i++)
        if (people[i].two == "No" && mySet.find(people[i].one) == mySet.end())
            sum++;
    cout << sum << endl;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值