您的位置:首页 > 其它

1072. 开学寄语(20)

2018-03-04 12:01 197 查看
1072. 开学寄语(20)

时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B

判题程序 Standard 作者 CHEN, Yue

下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其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

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <set>

using namespace std;
const int MaxN = 1010;
struct stu
{
string name;
vector<int>List;
}Stu[MaxN];

set<int>confList;

int main()
{
#ifdef _DEBUG
freopen("data.txt", "r+", stdin);
#endif // _DEBUG
std::ios::sync_with_stdio(false);

int N, M,SN = 0;
cin >> N >> M;
for (int i = 0; i < M; ++i)
{
int id;
cin >> id;
confList.insert(id);
}

for (int i = 0; i < N; ++i)
{
string name; int num, id; bool flag = false;
vector<int> clist;
cin >> name >> num;
for (int k = 0; k < num; ++k)
{
cin >> id;
if (confList.find(id) != confList.end())
{
flag = true;
clist.push_back(id);
}
}
if (flag)
{
Stu[SN].name = name;
Stu[SN++].List = clist;
}
}

int allN = 0;
for (int i = 0; i < SN; ++i)
{
cout << Stu[i].name << ": ";
for (int k = 0; k < Stu[i].List.size(); ++k)
{
cout << setfill('0') << setw(4) << Stu[i].List[k];
if (k != Stu[i].List.size() - 1)cout << " ";
}
allN += Stu[i].List.size();
cout << endl;
}

cout << SN << " " << allN;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  pat乙级 1072