1122. Prerequisites?

题意:

第一行输入n, m;分别表示的是该同学总共选了n门课程和改同学需要修的m种课程
接下来是m行,每一行首先由两个数字假设为a, b;
a 表示的是这个种类的课程总共有a门,b表示该同学至少需要修读b们改类课程
如果该同学有哪一类课程不满足要求则不能够毕业,输出”no”,否则输出”yes”

Sample Input

3 2
0123 9876 2222
2 1 8888 2222
3 2 9876 2222 7654
3 2
0123 9876 2222
2 2 8888 2222
3 2 7654 9876 2222
0

Sample Output

yes
no

代码实现:

注: set, s.count(temp) != 0, s.insert(str);

#include<iostream>
#include<set>
#include<cstring>
using namespace std;

int main() {
    int course, category;
    int total, min, count, counter;
    bool flag = false, anotherflag;
    string temp;
    while (cin >> course && course) {
        set<string> s;
        cin >> category;
        anotherflag = true;
        for (int i = 0; i < course; ++i) {
            cin >> temp;
            s.insert(temp);
        }
        counter = 0;
        for (int i = 0;  i < category; ++i) {
            cin >> total >> min;
            count = 0;
            flag = false;
            for (int j = 0; j < total; ++j) {
                cin >> temp;
                if (s.count(temp)) count++;
                if (count >= min) {
                    flag = true;
                }
            }
            if (flag == false) anotherflag = false;  // 只要有一个不满足条件就是no
        }
        if (anotherflag) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值