PAT甲级1121 Damn Single
“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相关推荐
- PAT甲级1121 Damn Single :[C++题解]哈希表、结构体
文章目录 题目分析 题目来源 题目分析 来源:acwing 思路:一对伴侣存入一个结构体中.查询的集合放入哈希表unordered_set<int> S;中.然后遍历每一对伴侣,如果同时存 ...
- PAT 甲级 1121 Damn Single
1121 Damn Single (25 point(s)) "Damn Single (单身狗)" is the Chinese nickname for someone who ...
- PAT 甲级1121 Damn Single
1121 Damn Single "Damn Single (单身狗)" is the Chinese nickname for someone who is being sing ...
- PAT甲级 1121. Damn Single (25)
1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...
- 【PAT】1121. Damn Single (25)【哈希表】
题目描述 "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are ...
- PAT——1121 Damn Single 甲级
1121 Damn Single 题目 题意 代码解析 AC代码 参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/99 ...
- 【PAT甲级真题整理五】1121~1155
终于考完了qaq把最后一堆也整理出来了 目录 1121 Damn Single(25)set.map的使用 1122 Hamiltonian Cycle(25)哈密顿回路 1123 Is It a C ...
- PAT 1121 Damn Single
1121 Damn Single "Damn Single (单身狗)" is the Chinese nickname for someone who is being sing ...
- PAT甲级考试题库题目分类
PAT甲级题目分类 水题 1136.1139.1143.1148 字符串处理 1001.1005.1035.1061.1073.1077.1082. 1108.1140.1152 模拟 1002.10 ...
最新文章
- 模拟linux文件系统的设计及实现_Linux后台服务器开发中,内存池设计与实现(c/c++)...
- 基于WINCE6.0下载multiple XIP镜像文件
- sleep防止CPU占用100%
- leetcode 21 合并两个有序链表 C++
- pythonrandom库seed_Python
- 机器学习实战(Machine Learning in Action)学习笔记————06.k-均值聚类算法(kMeans)学习笔记...
- git pull push 项目的时候总是提示要输入用户名密码的解决方案
- 驱动精灵修复服务器,驱动精灵系统漏洞需要修复吗
- 虚拟机安装win7时遇到的问题及解决方案
- java 设置图片大小_java 用这个方法如何设置图片大小
- 做正确的事和正确的做事
- win7网络适配器_win7网络重置
- Apache 重写规则及参数详解,入门看这个就够了
- WebStorm-2021.1.1下载及安装
- 如何用计算机学唱歌,男孩学唱歌教程 男生如何练习唱歌?
- LinkedList底层链表结构
- HTML网页设计文件的组成
- STM32红外寻迹小车
- 达内培训python费用
- 离散数学_第二章:基本结构:集合、函数、序列、求和和矩阵(1)