作者:手机用户2502925683 | 来源:互联网 | 2023-10-10 09:35
篇首语:本文由编程笔记#小编为大家整理,主要介绍了PTA 乙级 (1072 开学寄语 (20分))相关的知识,希望对你有一定的参考价值。
1072 开学寄语 (20分)
https://pintia.cn/problem-sets/994805260223102976/problems/994805263964422144
第一次:格式错误
第二次:AC
两种方法:
1 #include <iostream>
2 #include
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 ) {
9 scanf("%d", &temp);
10 forbid[temp] = true;
11 }
12 for (int i = 0; i ) {
13 char name[10];
14 bool flag = false;
15 scanf("%s %d", name, &k);
16 for (int j = 0; 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
2 #include
3 #include
4 #include <string>
5 #include
6 #include
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>str[i];
17 int count1=0,count2=0,amount;
18 for(i=0;i)
19 {
20 flag=false;
21 cin>>chr;
22 cin>>amount;
23 for(j=0;j)
24 {
25 cin>>str1;
26 for(k=0;k)
27 {
28 if(str1==str[k])
29 {
30 count2++;
31 if(flag==false)
32 {cout<":";count1++;}
33 cout<<" "<<str1;
34 flag=true;
35 }
36 }
37 }
38 if(flag) cout<<"
"; //加了这一行,没加之前老是格式错误
39 }
40 cout<" "<<count2;
41 return 0;
42 }