1072 开学寄语
Posted gzu_zb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1072 开学寄语相关的知识,希望对你有一定的参考价值。
题目链接: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 }
以上是关于1072 开学寄语的主要内容,如果未能解决你的问题,请参考以下文章