题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805263964422144
基本一遍过,注意if里面双等号不要漏打一个等号

代码

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<string>
  4. #include<vector>
  5. #include<map>
  6. using namespace std;
  7. map<int ,int> ban_list;
  8. map<string, bool> per_list;
  9. int main(){
  10. int n, m, k, temp_int, count1 = 0;
  11. scanf("%d%d", &n, &m);
  12. string temp_str;
  13. for(int i = 0; i < m; i++){
  14. scanf("%d", &k);
  15. ban_list[k]++;
  16. }
  17. for(int i = 0; i < n; i++){
  18. cin>>temp_str>>k;
  19. int flag = 0;
  20. per_list[temp_str] = false;
  21. for(int j = 0; j < k; j++){
  22. scanf("%d" ,&temp_int);
  23. if(ban_list[temp_int] != 0){
  24. if(flag == 0){
  25. flag = 1;
  26. cout<<temp_str + ":";
  27. }
  28. printf(" %04d", temp_int);
  29. per_list[temp_str] = true;
  30. count1 ++;
  31. }
  32. }
  33. if(flag == 1)printf("\n");
  34. }
  35. int count2 = 0;
  36. for(auto it = per_list.begin(); it != per_list.end(); it++){
  37. if(it->second) count2++;
  38. }
  39. printf("%d %d", count2, count1);
  40. }