PAT 1072 开学寄语

https://pintia.cn/problem-sets/994805260223102976/problems/994805263964422144

1072 开学寄语(20 分)提问

下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使其百无聊赖,然后,净面、理发、整衣,然后思过、读书、锻炼、明智、开悟、精进。而后必成大器也!

本题要求你写个程序帮助这所学校的老师检查所有学生的物品,以助其成大器。

输入格式:

输入第一行给出两个正整数 N(≤ 1000)和 M(≤ 6),分别是学生人数和需要被查缴的物品种类数。第二行给出 M 个需要被查缴的物品编号,其中编号为 4 位数字。随后 N 行,每行给出一位学生的姓名缩写(由 1-4 个大写英文字母组成)、个人物品数量 K(0 ≤ K ≤ 10)、以及 K 个物品的编号。

输出格式:

顺次检查每个学生携带的物品,如果有需要被查缴的物品存在,则按以下格式输出该生的信息和其需要被查缴的物品的信息(注意行末不得有多余空格):

姓名缩写: 物品编号1 物品编号2 ……

最后一行输出存在问题的学生的总人数和被查缴物品的总数。

输入样例:

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

代码:
#include <bits/stdc++.h>
using namespace std;

int thing[1111],u[1111];

struct students {
    char name[10];
    int n;
    int number[20];
}s[1111];

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    int ans1 = 0, ans2 = 0;
    for(int i = 1; i <= M; i ++) {
        scanf("%d", &thing[i]);
    }

    for(int i = 1; i <= N; i ++) {
        scanf("%s%d", s[i].name, &s[i].n);
            for(int j = 1; j <= s[i].n; j ++)
            scanf("%d", &s[i].number[j]);
    }

    for(int j = 1; j <= N; j ++) {
            int sum = 0;
        for(int k = 1; k <= s[j].n; k++) {
            for(int i = 1; i <= M; i ++) {
                if(thing[i] == s[j].number[k]) {
                    u[sum ++] = s[j].number[k];
                    ans2 ++;
                }
            }
        }
        if(sum == 0) continue;
        ans1 ++;
        printf("%s:", s[j].name);
        for(int i = 0; i < sum; i ++) {
            printf(" %04d",u[i]);
        }
        printf("\n");
    }
    printf("%d %d\n", ans1, ans2);
    return 0;
}

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9380131.html

时间: 2024-08-02 04:23:01

PAT 1072 开学寄语的相关文章

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行,每行给出一位学生的姓名缩写

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 stri

PAT_B_1072 开学寄语

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

PAT 1072. Gas Station (30)

A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible.  However it must guarantee that all the houses are in its service range. Now given the map o

PAT 1072 Gas Station[图论][难]

1072 Gas Station (30)(30 分) A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the houses are in its service

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(

PAT甲题题解-1072. Gas Station (30)-dijkstra最短路

题意:从m个加油站里面选取1个站点,使得其离住宅的最近距离mindis尽可能地远,并且离所有住宅的距离都在服务范围ds之内.如果有很多相同mindis的加油站,输出距所有住宅平均距离最小的那个.如果平均值还是一样,就输出按照顺序排列加油站编号最小的. 分析:加油站之间也是彼此有路连接的,所以最短路径计算的时候也要把加油站算上,是双向边,所以边的数组大小得开两倍.加油站编号记为n+1~n+m,对这些点用dijkstra计算最短路径即可,这里顺便在dijkstra中进行了剪枝处理,不剪枝也没事. #

PAT (Advanced Level) 1072. Gas Station (30)

枚举一下选的位置,每次算一下就可以了. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; const int