PAT乙级1072-----开学寄语 (20分)

1072 开学寄语 (20分)

输入样例:

4 2
2333 6666
CYLL 3 1234 2345 3456
U 4 9966 6666 8888 6666
GG 2 2333 7777
JJ 3 0012 6666 2333

输出样例:

U: 6666 6666
GG: 2333
JJ: 6666 2333
3 5

思路:1.用数组下标表示违禁物品编号2.不满4位数要补0,例如:编号12输出时为0012

首次通过代码:

 1 #include<stdio.h>
 2
 3 int main(){
 4     int n,m;int num[10004]={0};
 5     scanf("%d %d",&n,&m);
 6     for(int i=0;i<m;i++){
 7         int a;
 8        scanf("%d",&a);
 9        num[a]=1;
10     }
11     int counter_student=0;int counter_goods=0;
12     for(int i=0;i<n;i++){
13         char name[6];int a;int c1=0;
14         scanf("%s %d",name,&a);
15         for(int j=0;j<a;j++){
16             int b;
17             scanf("%d",&b);
18             if(num[b]==1){
19                 if(c1==0) {
20                   if(counter_student!=0) printf("\n");
21                   printf("%s: ",name);
22                   if(b<1000&&b>=100) printf("0");
23                   else if(b<100&&b>=10) printf("00");
24                   else if(b<10)  printf("000");
25                   printf("%d",b);
26                   counter_student++;c1++;
27                 }
28                 else {
29                   printf(" ");
30                   if(b<1000&&b>=100) printf("0");
31                   else if(b<100&&b>=10) printf("00");
32                   else if(b<10)  printf("000");
33                  printf("%d",b);
34                  c1++;
35                 }
36             }
37         }
38         counter_goods+=c1;
39     }
40     if(counter_student>0) printf("\n%d %d",counter_student,counter_goods);
41     else printf("0 0");
42     return 0;
43 }

 

原文地址:https://www.cnblogs.com/a982961222/p/12386431.html

时间: 2024-10-01 10:34:17

PAT乙级1072-----开学寄语 (20分)的相关文章

PAT Basic 1072 开学寄语 (20 分)

下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使其百无聊赖,然后,净面.理发.整衣,然后思过.读书.锻炼.明智.开悟.精进.而后必成大器也! 本题要求你写个程序帮助这所学校的老师检查所有学生的物品,以助其成大器. 输入格式: 输入第一行给出两个正整数 N(≤ 1000)和 M(≤ 6),分别是学生人数和需要被查缴的物品种类数.第二行给出 M 个需要被查缴的物品编号,其中编号为 4 位数字.随后 N 行,每行给出一

1072. 开学寄语(20)

下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其QQ,封其电脑,夺其手机,收其ipad,断其wifi,使其百无聊赖,然后,净面.理发.整衣,然后思过.读书.锻炼.明智.开悟.精进.而后必成大器也! 本题要求你写个程序帮助这所学校的老师检查所有学生的物品,以助其成大器. 输入格式: 输入第一行给出两个正整数N(<= 1000)和M(<= 6),分别是学生人数和需要被查缴的物品种类数.第二行给出M个需要被查缴的物品编号,其中编号为4位数字.随后N行,每行给出一位学生的姓名缩写

PAT 1072 开学寄语

https://pintia.cn/problem-sets/994805260223102976/problems/994805263964422144 1072 开学寄语(20 分)提问 下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使其百无聊赖,然后,净面.理发.整衣,然后思过.读书.锻炼.明智.开悟.精进.而后必成大器也! 本题要求你写个程序帮助这所学校的老师检查所有学生的物品,以助其成大器. 输入格式:

PAT乙级1034. 有理数四则运算(20)

本题要求编写程序,计算2个有理数的和.差.积.商. 输入格式: 输入在一行中按照“a1/b1 a2/b2”的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前,分母不为0. 输出格式: 分别在4行中按照“有理数1 运算符 有理数2 = 结果”的格式顺序输出2个有理数的和.差.积.商.注意输出的每个有理数必须是该有理数的最简形式“k a/b”,其中k是整数部分,a/b是最简分数部分:若为负数,则须加括号:若除法分母为0,则输出“Inf”.题目保证正确的输出中没

pat 1015 Reversible Primes(20 分)

1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime. Now given a

pat 1042 Shuffling Machine(20 分)

1042 Shuffling Machine(20 分) Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing

pat 1050 String Subtraction(20 分)

1050 String Subtraction(20 分) Given two strings S?1?? and S?2??, S=S?1???S?2?? is defined to be the remaining string after taking all the characters in S?2?? from S?1??. Your task is simply to calculate S?1???S?2?? for any given strings. However, it

pat 1041 Be Unique(20 分)

1041 Be Unique(20 分) Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1,10?4??]. The first one who bets on a unique number wins. For e

pat 1046 Shortest Distance(20 分) (线段树)

1046 Shortest Distance(20 分) The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits. Input Specification: Each input file contains one test case. For