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
//初始化用用-1
//因为有人的编号可能是00000
//所以第二个点不过 
#include<cstdio>
const int maxn = 100010;int spouse[maxn] = {0};int main(){int n,id1,id2;for(int i = 0; i < maxn; i++) spouse[i] = -1; scanf("%d",&n);while(n--){scanf("%d%d",&id1,&id2);spouse[id1] = id2;spouse[id2] = id1;  }scanf("%d",&n);while(n--){scanf("%d",&id1);if(spouse[id1] >= 0 && spouse[spouse[id1]] >= 0){spouse[id1] = -2;}else if(spouse[id1] >= 0 &&spouse[spouse[id1]] == -2){spouse[spouse[id1]] = 2;}else{spouse[id1] = -3;}}int cnt = 0;for(int i = 0; i < maxn; i++){if(spouse[i] < -1) cnt++;}printf("%d\n",cnt);for(int i = 0; i < maxn; i++){if(spouse[i] < -1){printf("%05d",i);cnt--;if(cnt > 0) printf(" ");}    }return 0;
}

 

转载于:https://www.cnblogs.com/wanghao-boke/p/10453470.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/385133.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

1124 Raffle for Weibo Followers (20 分)

John got a full mark on PAT. He was so happy that he decided to hold a raffle&#xff08;抽奖&#xff09; for his followers on Weibo -- that is, he would select winners from every N followers who forwarded his post, and give away gifts. Now you are suppose…

987. 二叉树的垂序遍历

给定二叉树&#xff0c;按垂序遍历返回其结点值。 对位于 (X, Y) 的每个结点而言&#xff0c;其左右子结点分别位于 (X-1, Y-1) 和 (X1, Y-1)。 把一条垂线从 X -infinity 移动到 X infinity &#xff0c;每当该垂线与结点接触时&#xff0c;我们按从上到下的顺序报告结点的值…

28. 实现 strStr()

实现 strStr() 函数。 给定一个 haystack 字符串和一个 needle 字符串&#xff0c;在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在&#xff0c;则返回 -1。 示例 1: 输入: haystack "hello", needle "ll" 输出: 2 示例…

1136 A Delayed Palindrome (20 分)

Consider a positive integer N written in standard notation with k1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ with 0 for all i and a​k​​>0. Then N is palindromic if and only if a​i​​a​k−i​​ for all i. Zero is written 0 and is also palindrom…

1044 火星数字 (20 分)

火星人是以 13 进制计数的&#xff1a; 地球人的 0 被火星人称为 tret。地球人数字 1 到 12 的火星文分别为&#xff1a;jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。火星人将进位以后的 12 个高位数字分别称为&#xff1a;tam, hel, maa, huh, tou, kes, he…

43. 字符串相乘

给定两个以字符串形式表示的非负整数 num1 和 num2&#xff0c;返回 num1 和 num2 的乘积&#xff0c;它们的乘积也表示为字符串形式。 示例 1: 输入: num1 "2", num2 "3" 输出: "6" 示例 2: 输入: num1 "123", num2 "456&qu…

1045 快速排序 (25 分)

著名的快速排序算法里有一个经典的划分过程&#xff1a;我们通常采用某种方法取一个元素作为主元&#xff0c;通过交换&#xff0c;把比主元小的元素放到它的左边&#xff0c;比主元大的元素放到它的右边。 给定划分后的 N 个互不相同的正整数的排列&#xff0c;请问有多少个元…

1049 数列的片段和 (20 分)

给定一个正数数列&#xff0c;我们可以从中截取任意的连续的几个数&#xff0c;称为片段。例如&#xff0c;给定数列 { 0.1, 0.2, 0.3, 0.4 }&#xff0c;我们有 (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4) (0.3) (0.3, 0.4) (0…

C++ Priemer目录索引

序号内容1 【C Primer | 15】虚函数表剖析&#xff08;一&#xff09; 2 【C Priemr | 15】虚函数表剖析&#xff08;二&#xff09; 3 【C Priemr | 15】虚函数表剖析&#xff08;三&#xff09; 4一个C程序执行main函数前和执行完main函数后会发生什么。1 【C Priemr | 15】虚…

1046 划拳 (15 分)

划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为&#xff1a;每人口中喊出一个数字&#xff0c;同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和&#xff0c;谁就赢了&#xff0c;输家罚一杯酒。两人同赢或两人同输则继续下一轮&…

多线程顺序交替打印ABCD

题目&#xff1a;按照 ABCD的顺序交替打印。 1. 测试代码&#xff1a; #include <iostream> #include <unistd.h> #include <stdlib.h> #include <pthread.h> using namespace std;struct {int t;pthread_mutex_t mutex;pthread_cond_t cond; } tes…

第一个只出现一次的字符

在一个字符串(0<字符串长度<10000&#xff0c;全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置, 如果没有则返回 -1&#xff08;需要区分大小写&#xff09;. 解法&#xff1a; class Solution { public:int FirstNotRepeatingChar(string str) {unordered…

《Leetcode》目录

序号题目题解标记1 43. 字符串相乘 字符串2513. 找树左下角的值二叉树3 450. 删除二叉搜索树中的节点 二叉树486. 分隔链表链表155 155. 最小栈 C题解栈77. 组合C题解回溯算法15.三数之和C题解

一个C++程序执行main函数前和执行完main函数后会发生什么。

总结&#xff1a; main函数执行之前&#xff0c;主要就是初始化系统相关资源&#xff1a; 设置栈指针初始化static静态和global全局变量&#xff0c;即data段的内容将未初始化部分的赋初值&#xff1a;数值型short&#xff0c;int&#xff0c;long等为0&#xff0c;bool为FALS…

1144 The Missing Number (20 分)

Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list. Input Specification: Each input file contains one test case. For each case, the first line gives a positive integer N (≤10​5​​). Then N integers are…

【面试宝典 | 01】面经

字节跳动提前批后端第三面凉经该来的终究会来的

1148 Werewolf - Simple Version (20 分)

Werewolf&#xff08;狼人杀&#xff09; is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game, player #1 said: "Player #2 is a werewolf.";player #2 said: "Player #3 is a h…

算法默写

序号内容1快速排序算法2堆排序算法3归并排序算法

1149 Dangerous Goods Packaging (25 分)

When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we might get ourselves in serious trouble. For example, oxidizing agent &#xff08;氧化剂&#xff09; must not be packed with flamma…

《数据结构与算法》

序号内容1排序算法概念2快速排序算法3堆排序算法4归并排序算法