前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PAT(甲级)1121.Damn Single(25)

PAT(甲级)1121.Damn Single(25)

作者头像
lexingsen
发布2022-02-25 08:06:09
2440
发布2022-02-25 08:06:09
举报
文章被收录于专栏:乐行僧的博客

PAT 1121.Damn Single(25分)

“Damn Single (单身狗)” is the Chinese nickname for someone who is being single. You are supposed to find those who are alone in a big party, so they can be taken care of.

输入格式:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤ 50,000), the total number of couples. Then N lines of the couples follow, each gives a couple of ID’s which are 5-digit numbers (i.e. from 00000 to 99999). After the list of couples, there is a positive integer M (≤ 10,000) followed by M ID’s of the party guests. The numbers are separated by spaces. It is guaranteed that nobody is having bigamous marriage (重婚) or dangling with more than one companion.

输出格式:

First print in a line the total number of lonely guests. Then in the next line, print their ID’s in increasing order. The numbers must be separated by exactly 1 space, and there must be no extra space at the end of the line.

输入样例:

代码语言:javascript
复制
3
11111 22222
33333 44444
55555 66666
7
55555 44444 10000 88888 22222 11111 23333

输出样例:

代码语言:javascript
复制
5
10000 23333 44444 55555 88888

题目分析:乙级1065的一个题目,具体分析请看乙级1065

注意:输出格式为%05d,否则测试点3会出错。

AC代码:

代码语言:javascript
复制
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 100000;

bool is_appear[maxn] = {false};

vector<int>v;
unordered_map<int, int> mp;
int main(){
    //freopen("in.txt", "r", stdin);
    int n, a, b;
    scanf("%d", &n);
    for(int i=0; i<n; ++i){
        scanf("%d%d", &a, &b);
        mp.insert(make_pair(a, b));
    }
    int m, tmp;
    scanf("%d", &m);
    for(int i=0; i<m; ++i){
        scanf("%d", &tmp);
        is_appear[tmp] = true;
    }
    for(auto it=mp.begin(); it!=mp.end(); ++it){
        if(is_appear[it->first] && is_appear[it->second]){
            is_appear[it->first] = is_appear[it->second] = false;
        }
    }
    for(int i=0; i<maxn; ++i){
        if(is_appear[i])
            v.push_back(i);
    }
    sort(v.begin(), v.end());
    for(int i=0; i<v.size(); ++i){
        printf("%05d", v[i]);
        if(i!=v.size()-1)printf(" ");
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

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

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

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