1072 开学寄语 (20分)
https://pintia.cn/problem-sets/994805260223102976/problems/994805263964422144
第一次:格式错误
第二次:AC
两种方法:
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 bool forbid[10000]; 5 int main() { 6 int n, m, temp, k, snum = 0, fnum = 0; 7 scanf("%d %d", &n, &m); 8 for (int i = 0; i < m; i++) { 9 scanf("%d", &temp); 10 forbid[temp] = true; 11 } 12 for (int i = 0; i < n; i++) { 13 char name[10]; 14 bool flag = false; 15 scanf("%s %d", name, &k); 16 for (int j = 0; j < k; j++) { 17 scanf("%d", &temp); 18 if (forbid[temp]) { 19 if (!flag) { 20 printf("%s:", name); 21 flag = true; 22 } 23 printf(" %04d", temp); 24 fnum++; 25 } 26 } 27 if (flag) { 28 printf(" "); 29 snum++; 30 } 31 } 32 printf("%d %d ", snum, fnum); 33 return 0; 34 }
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <cmath> 6 #include <algorithm> 7 using namespace std; 8 int main() 9 { 10 int n,m; 11 string str[7],str1; 12 char chr[5]; 13 int i,j,k; 14 bool flag=false; 15 cin>>n>>m; 16 for(i=0;i<m;i++) cin>>str[i]; 17 int count1=0,count2=0,amount; 18 for(i=0;i<n;i++) 19 { 20 flag=false; 21 cin>>chr; 22 cin>>amount; 23 for(j=0;j<amount;j++) 24 { 25 cin>>str1; 26 for(k=0;k<m;k++) 27 { 28 if(str1==str[k]) 29 { 30 count2++; 31 if(flag==false) 32 {cout<<chr<<":";count1++;} 33 cout<<" "<<str1; 34 flag=true; 35 } 36 } 37 } 38 if(flag) cout<<" "; //加了这一行,没加之前老是格式错误 39 } 40 cout<<count1<<" "<<count2; 41 return 0; 42 }