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 ...
随机推荐
- 组合数学 - BZOJ 3997 - TJOI2015
TJOI2015 Problem's Link ---------------------------------------------------------------------------- ...
- C++ 函数的扩展①
//函数扩展--内联函数 inline #include<iostream> using namespace std; /* c++中const常量可以替代宏常数定义 如: const i ...
- 关于Unity屏幕分辨率的比例
1.Free Aspect任意窗口大小 2.16:9是1920*1080的手机 3.4:3是1024*768ipad 4.3:2是960*640,iPhone4手机屏幕 5.480*800,竖屏手机游 ...
- MRF能量优化
一个外国博客,写的比较清晰 http://nghiaho.com/?page_id=1366 MRF优化牛人 重庆大学的教授 1 http://qianjiye.de/2015/09/reparame ...
- Unity的 Stats 窗体, Batched、SetPass、Draw Call 等
孙广东 2015.8.12 在Game View 中的右上角有一个统计数据 Stats button.当按下button时.覆盖窗体显示,可用于优化性能的实时渲染统计信息. 确切的统计数据显示生成目 ...
- 在dropDownList中实现既能输入一个新值又能实现下拉选的代码
aspx: <div id="selDiv" style=" z-index:100; visibility:visible; clip:rect(0px 110p ...
- jQuery实现tag便签去重效果的方法
本文实例讲述了jQuery实现tag便签去重效果的方法.分享给大家供大家参考.具体实现方法如下: html代码如下: <head><script type="text/ja ...
- php7垃圾回收分析
- Laravel5.1 表单验证
当我们提交表单时 通常会对提交过来的数据进行一些验证.Laravel在Controller类中使用了一个traint:ValidatesRequest.方便我们在控制器中使用验证器. 下面我们就来看一 ...
- iOS开发之--沙盒的操作
iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. documents,tmp,app,Library. (NSHomeDirectory ...