PAT 1121 Damn Single[简单]
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.
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
题目大意:给出n对情侣,然后再给出m对参加宴会的人,判断这些人当中有多少人是没有伙伴来参加宴会的(本身已经结婚,但是没带伴侣来的也会被计算进来)
#include <iostream>
#include<vector>
#include<map>
using namespace std; map<string,string> m2f;
map<string,string> inp;
int main() {
int n;
cin>>n;
string x,y;
for(int i=;i<n;i++){
cin>>x>>y;
m2f[x]=y;
m2f[y]=x;
}
int m;
cin>>m;
string s;
for(int i=;i<m;i++){
cin>>s;
inp[s]=;//因为这里的map是自然排序的,所以最终vector里也是自然排序的。
}
int ct=;
vector<string> vt;
for(auto it=inp.begin();it!=inp.end();it++){
string str=it->first;
if(inp.count(m2f[str])==){
vt.push_back(str);
}
}
cout<<vt.size()<<'\n';
for(int i=;i<vt.size();i++){
cout<<vt[i];
if(i!=vt.size()-)cout<<" ";
}
return ;
}
//还是比较简单的,但是还是提交了两次,为什么呢?
1.需要主要最后的输出格式,是1!=vt.size()-1,知道了吗?
PAT 1121 Damn Single[简单]的更多相关文章
- PAT 1121 Damn Single
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...
- PAT甲级 1121. Damn Single (25)
1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...
- 1121 Damn Single (25 分)
1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...
- PTA 1121 Damn Single
题目链接:1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who i ...
- PAT甲题题解-1121. Damn Single (25)-水题
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789787.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT 1132 Cut Integer[简单]
1132 Cut Integer(20 分) Cutting an integer means to cut a K digits lone integer Z into two integers o ...
- PAT A1121 Damn Single (25 分)——set遍历
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...
- PAT 1089 狼人杀-简单版(20 分)(代码+测试点分析)
1089 狼人杀-简单版(20 分) 以下文字摘自<灵机一动·好玩的数学>:"狼人杀"游戏分为狼人.好人两大阵营.在一局"狼人杀"游戏中,1 号玩家 ...
- [PAT]A+B Format[简单]
1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...
随机推荐
- android 百度地图开发实例(转载)
因为在我的寝室google基站定位返回的数据总是为空,所以换成百度地图,发现百度地图开发起来非常方便,提供了许多有用的工具,地图的加载速度也比google地图快许多. 为了加强记忆,写一点androi ...
- 003很好的网络博客(TCP/IP)-很全
http://www.cnblogs.com/obama/p/3292335.html 很全的计算机网络方面的资料.
- 22SpringMvc_jsp页面上的数据传递到控制器的说明
假设有这个一个业务:在jsp页面上写入数据,然后把这个数据传递到后台. 效果如下:
- STL的map容器将第3个模板参数设为less_equal或greater_equal会怎样?
最近都在学Linux系统编程,用C就足矣,有段时间没碰C++了,于是实现些算法练手. 实现多项式乘法的时候发现有几项没有合并同类项,最终调试到这一步时发现了问题. res是map类型,用find查找k ...
- C# 将MSMQ消息转换成Json格式
PS:主要就是一个配置文件和一个转换函数 配置文件app.config 之前要ADD reference --> system.configuration & using.syst ...
- 怎么用ChemDraw加反应条件
众所周知大部分化学反应都需要在一定的条件下才会发生,比较常见的条件有压力.通电.温度.光照等等.这些特定条件在化学上就叫反应条件.我们在使用ChemDraw这款化学绘图软件的时候,往往需要给我们的化学 ...
- C++关键字之explicit(显式)
C++ Code 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 ...
- iOS 圆角投影
self.backgroundColor = [UIColor whiteColor]; self.layer.shadowColor = [UIColor lightGrayColor].CGCol ...
- 使用cordova+Ionic+AngularJs进行Hybird App开发的环境搭建手冊
一.所需工具 1,JDK:生成 2.安卓SDK开发环境 3,NodeJs:主要使用的还是npm 4,Python开发环境 5.VS 2012(2008,2015也能够,已亲測):安装这个主要是须要一些 ...
- ios开发之 -- 5分钟集成融云的客服功能
最近项目中遇到了客服的功能,首先想到的就是使用融云的功能,因为以前做的即时通讯的项目,用的都是融云的sdk,花了点时间研究了下,希望能帮到大家! 废话不多说,步骤如下: 一.申请融云账号 二.创建应用 ...