前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >1072 开学寄语 (20 分)

1072 开学寄语 (20 分)

作者头像
可爱见见
发布2019-10-30 11:28:02
3910
发布2019-10-30 11:28:02
举报
文章被收录于专栏:卡尼慕

【我的代码】

代码语言:javascript
复制
//1072 开学寄语 (20 分)
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main(){
    int N, M;
    cin>>N>>M;//学生人数和物品种类数
    map<int, int> m;
    int count = 0;
    int thing[M];
    int tmp;
    for(int i = 0; i < M; i++){
        cin>>tmp;
        m[tmp]++;
    } 
    string name;
    int tmp_tot;
    int wupin;
    int stu = 0; 
    for(int i = 0; i < N; i++){
        tmp_tot = 0;
        vector<int> t;
        cin>>name>>tmp;
        for(int j = 0; j < tmp; j++){
            cin>>wupin;
            if(m[wupin]){
                t.push_back(wupin); 
                count++;
                tmp_tot++;
            }
        }
        if(tmp_tot != 0){
            //说明有违禁物品
            cout<<name<<":";
            stu++;
            for(int i = 0; i < t.size(); i++){
                cout<<" ";
                printf("%04d",t[i]);
            }
            cout<<endl;
        }
    }
    cout<<stu<<" "<<count;
    return 0;
}

【思路】

  1. 使用map来保存违规的物品,方便搜索。
  2. 输出的时候要注意是四位数,否则测试点二错误!
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-10-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 卡尼慕 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档