题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805263964422144
题解:
1 #include <iostream> 2 #include<string> 3 using namespace std; 4 5 int main() { 6 int n, m; 7 cin >> n >> m; 8 int sum_row = 0, sum = 0; 9 string *need_find = new string[m]; 10 for (int i = 0; i < m; i++) 11 cin >> need_find[i]; 12 for (int i = 0; i < n; i++) { 13 string name; 14 int num; 15 cin >> name >> num; 16 string *flag_find = new string[num]; 17 for (int i = 0; i < num; i++) 18 cin >> flag_find[i]; 19 bool flag = false; 20 string *ans = new string[num]; 21 int k = 0; 22 for (int i = 0; i < num; i++) { 23 for (int j = 0; j < m; j++) { 24 if (flag_find[i] == need_find[j]) { 25 flag = true; 26 ans[k++] = flag_find[i]; 27 sum++; 28 } 29 } 30 } 31 if (flag) { 32 cout << name << ":"; 33 sum_row++; 34 for (int i = 0; i < k; i++) { 35 cout << " " << ans[i];//此处格式的控制容易错(行末不得有多余空格) 36 } 37 cout << endl; 38 } 39 } 40 cout << sum_row << " " << sum << endl; 41 return 0; 42 }
原文地址:https://www.cnblogs.com/Gzu_zb/p/9588472.html
时间: 2024-10-09 21:08:14