“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.

Input Specification:

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.

Output Specification:

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.

Sample Input:

3
11111 22222
33333 44444
55555 66666
7
55555 44444 10000 88888 22222 11111 23333

Sample Output:

5
10000 23333 44444 55555 88888

思路

PAT乙级1065 单身狗
这里没有复制,重新写了一遍

#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
map<int, int> cp;
map<int, bool> arrive;
int main()
{int N;cin >> N;for (int i = 0; i < N; i++){int a, b;cin >> a >> b;cp[a] = b;cp[b] = a;}int M;cin >> M;vector<int> party;for (int i = 0; i < M; i++){int guest;cin >> guest;party.push_back(guest);arrive[guest] = true;}vector<int> single;for (int i = 0; i < party.size(); i++){if (cp.find(party[i]) != cp.end()){if (arrive.find(cp[party[i]]) == arrive.end())single.push_back(party[i]);}elsesingle.push_back(party[i]);}sort(single.begin(), single.end());cout << single.size() << endl;for (int i = 0; i < single.size(); i++){if (i != 0)printf(" ");printf("%05d", single[i]);}system("pause");return 0;
}

PAT甲级1121 Damn Single相关推荐

  1. PAT甲级1121 Damn Single :[C++题解]哈希表、结构体

    文章目录 题目分析 题目来源 题目分析 来源:acwing 思路:一对伴侣存入一个结构体中.查询的集合放入哈希表unordered_set<int> S;中.然后遍历每一对伴侣,如果同时存 ...

  2. PAT 甲级 1121  Damn Single

    1121 Damn Single (25 point(s)) "Damn Single (单身狗)" is the Chinese nickname for someone who ...

  3. PAT 甲级1121 Damn Single

    1121 Damn Single "Damn Single (单身狗)" is the Chinese nickname for someone who is being sing ...

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

    1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...

  5. 【PAT】1121. Damn Single (25)【哈希表】

    题目描述 "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are ...

  6. PAT——1121 Damn Single 甲级

    1121 Damn Single 题目 题意 代码解析 AC代码 参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/99 ...

  7. 【PAT甲级真题整理五】1121~1155

    终于考完了qaq把最后一堆也整理出来了 目录 1121 Damn Single(25)set.map的使用 1122 Hamiltonian Cycle(25)哈密顿回路 1123 Is It a C ...

  8. PAT 1121 Damn Single

    1121 Damn Single "Damn Single (单身狗)" is the Chinese nickname for someone who is being sing ...

  9. PAT甲级考试题库题目分类

    PAT甲级题目分类 水题 1136.1139.1143.1148 字符串处理 1001.1005.1035.1061.1073.1077.1082. 1108.1140.1152 模拟 1002.10 ...

最新文章

  1. 模拟linux文件系统的设计及实现_Linux后台服务器开发中,内存池设计与实现(c/c++)...
  2. 基于WINCE6.0下载multiple XIP镜像文件
  3. sleep防止CPU占用100%
  4. leetcode 21 合并两个有序链表 C++
  5. pythonrandom库seed_Python
  6. 机器学习实战(Machine Learning in Action)学习笔记————06.k-均值聚类算法(kMeans)学习笔记...
  7. git pull push 项目的时候总是提示要输入用户名密码的解决方案
  8. 驱动精灵修复服务器,驱动精灵系统漏洞需要修复吗
  9. 虚拟机安装win7时遇到的问题及解决方案
  10. java 设置图片大小_java 用这个方法如何设置图片大小
  11. 做正确的事和正确的做事
  12. win7网络适配器_win7网络重置
  13. Apache 重写规则及参数详解,入门看这个就够了
  14. WebStorm-2021.1.1下载及安装
  15. 如何用计算机学唱歌,男孩学唱歌教程 男生如何练习唱歌?
  16. LinkedList底层链表结构
  17. HTML网页设计文件的组成
  18. STM32红外寻迹小车
  19. 达内培训python费用
  20. 离散数学_第二章:基本结构:集合、函数、序列、求和和矩阵(1)

热门文章

  1. 专业术语 EVT、DVT、PVT的含义
  2. 掌财社:Python 机器学习工具包SKlearn的安装与使用
  3. 全平台EPUB阅读器-Neat Reader
  4. 为什么接吻的时候一定要紧闭双眼?
  5. 【js】onchange事件不被触发
  6. 简述 Linux DRM 架构
  7. Qcom平台 Camera 之常见错误和问题
  8. 未来侠机器人教育:不能脱离教育的本质去谈机器人教育培训
  9. DNSPod十问云开发宁鹏伟:重新定义开发
  10. paypal 主要的html 表格变量的含义