博客
关于我
PAT——1065. 单身狗
阅读量:463 次
发布时间:2019-03-06

本文共 2157 字,大约阅读时间需要 7 分钟。

“单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱。

输入格式:

输入第一行给出一个正整数N(<=50000),是已知夫妻/伴侣的对数;随后N行,每行给出一对夫妻/伴侣——为方便起见,每人对应一个ID号,为5位数字(从00000到99999),ID间以空格分隔;之后给出一个正整数M(<=10000),为参加派对的总人数;随后一行给出这M位客人的ID,以空格分隔。题目保证无人重婚或脚踩两条船。

输出格式:

首先第一行输出落单客人的总人数;随后第二行按ID递增顺序列出落单的客人。ID间用1个空格分隔,行的首尾不得有多余空格。

输入样例:

311111 2222233333 4444455555 66666755555 44444 10000 88888 22222 11111 23333

输出样例:

510000 23333 44444 55555 88888
1 import java.util.Scanner; 2 public class Main { 3  4     public static void main(String[] args) { 5         int N= 100000; 6         Scanner in = new Scanner(System.in); 7         int n = in.nextInt(); 8         int[] hasbandWife = new int[N]; 9         for (int i = 0; i < n; i++) {10             int a = in.nextInt();            11             int b = in.nextInt();            12             hasbandWife[a] = b;                13             hasbandWife[b] = a;14         }15         int m = in.nextInt();                16         int[] test = new int[m];17         for (int i = 0; i < m; i++) {18             test[i] = in.nextInt();19         }20         21         for (int i = 0; i < m; i++) {22             if (hasbandWife[test[i]] == 0) {23                 hasbandWife[test[i]]=-1;            24             }25             else if(hasbandWife[test[i]]==-1) {26                 27             }28             else if(hasbandWife[test[i]]==1){29                 30             }31             else {32                 for (int j = i+1; j < m; j++) {33                     if (hasbandWife[test[i]]==test[j]) {34                         hasbandWife[test[i]] = 1;        35                         hasbandWife[test[j]] = 1;            36                         break;37                     }38                 }39                 if (hasbandWife[test[i]]!=1) {            40                     hasbandWife[test[i]]=-1;41                 }42             }43         }44         45         int cnt = 0;46         for (int i = 0; i < N; i++) {47             if (hasbandWife[i]==-1) {48                 cnt++;49             }50         }51         52         System.out.println(cnt);53         54         int flag =1;  55         for(int i=0 ;i

 

转载地址:http://pnnbz.baihongyu.com/

你可能感兴趣的文章
MSTP是什么?有哪些专有名词?
查看>>
Mstsc 远程桌面链接 And 网络映射
查看>>
Myeclipse常用快捷键
查看>>
MyEclipse用(JDBC)连接SQL出现的问题~
查看>>
myeclipse的新建severlet不见解决方法
查看>>
MyEclipse设置当前行背景颜色、选中单词前景色、背景色
查看>>
myeclipse配置springmvc教程
查看>>
MyEclipse配置SVN
查看>>
MTCNN 人脸检测
查看>>
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>
MySQL
查看>>
MySQL
查看>>
mysql
查看>>
MTK Android 如何获取系统权限
查看>>
MySQL - 4种基本索引、聚簇索引和非聚索引、索引失效情况、SQL 优化
查看>>
MySQL - ERROR 1406
查看>>
mysql - 视图
查看>>
MySQL - 解读MySQL事务与锁机制
查看>>