陌陌的pat乙级题解 题解 小逻辑程序比较简单,整个过程就是保存和查找为了方便的查找我用了set保存违禁物品输入人的数据的时候,定义一个bool f来标记是不是有违禁物品以及如果有违禁物品是不是这个人的第一个如果是这个人的第一个违禁物品,那么需要输出这个人的名字 Code #include <iostream> #include <set> using namespace std; int main() { int N, M; cin >> N >> M; int cnt_1, cnt_2; cnt_1 = cnt_2 = 0; set<string> ret; string s; while (M--) { cin >> s; ret.insert(s); } while (N--) { int k; string id; cin >> id >> k; bool f = false; while (k--) { cin >> s; if (ret.count(s)) { if (!f) { f = true; cout << id << ":"; cnt_1++; } cnt_2++; cout << " " << s; } } if (f) cout << endl; } cout << cnt_1 << " " << cnt_2; return 0; }