码迷,mamicode.com
首页 > 其他好文 > 详细

PTA 乙级 (1072 开学寄语 (20分))

时间:2020-01-18 21:13:11      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:style   图片   problems   lag   div   cout   ret   names   cst   

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("\n");
29             snum++;
30         }
31     }
32     printf("%d %d\n", 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<<"\n";    //加了这一行,没加之前老是格式错误
39     }
40     cout<<count1<<" "<<count2;
41     return 0;
42 }

PTA 乙级 (1072 开学寄语 (20分))

标签:style   图片   problems   lag   div   cout   ret   names   cst   

原文地址:https://www.cnblogs.com/jianqiao123/p/12210044.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!