题意:
第一行输入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;
}