博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[PAT] 1041 Be Unique (20 分)Java
阅读量:5011 次
发布时间:2019-06-12

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

Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1,104​​]. The first one who bets on a unique number wins. For example, if there are 7 people betting on { 5 31 5 88 67 88 17 }, then the second one who bets on 31 wins.

Input Specification:

Each input file contains one test case. Each case contains a line which begins with a positive integer N (105​​) and then followed by N bets. The numbers are separated by a space.

Output Specification:

For each test case, print the winning number in a line. If there is no winner, print None instead.

Sample Input 1:

7 5 31 5 88 67 88 17

Sample Output 1:

31

Sample Input 2:

5 888 666 666 888 888

Sample Output 2:

None
1 package pattest; 2  3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.io.InputStreamReader; 6 import java.util.ArrayList; 7 import java.util.List; 8  9 /**10  * @Auther: Xingzheng Wang11  * @Date: 2019/2/22 13:5112  * @Description: pattest13  * @Version: 1.014  */15 public class PAT1041 {16     public static void main(String[] args) throws IOException {17         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));18         String[] sp = reader.readLine().split(" ");19 20         List
list1 = new ArrayList<>();21 List
list2 = new ArrayList<>();22 for (int i = 1; i < sp.length; i++) {23 if (list1.contains(sp[i])){24 list2.add(sp[i]);25 }else{26 list1.add(sp[i]);27 }28 }29 list1.removeAll(list2);30 if (list1.size() > 0){31 System.out.print(list1.get(0));32 }else{33 System.out.print("None");34 }35 }36 }

 

转载于:https://www.cnblogs.com/PureJava/p/10498067.html

你可能感兴趣的文章
编译安装mysql-5.6.40
查看>>
年终总结
查看>>
初创互联网公司技术架构变迁之路
查看>>
【BZOJ 3676】 3676: [Apio2014]回文串 (SAM+Manacher+倍增)
查看>>
【网络流24题】No. 13 星际转移问题 (网络判定 最大流)
查看>>
解析$.grep()源码及透过$.grep()看(两次取反)!!的作用
查看>>
[模板] 字符串hash
查看>>
SGU438_The Glorious Karlutka River =)
查看>>
Linux集群及LVS简介
查看>>
简单几何(直线与圆的交点) ZOJ Collision 3728
查看>>
Codeforces Round #327 (Div. 2)
查看>>
如何解决Provisional headers are shown问题(转)
查看>>
开发网站遇到的bug
查看>>
实现简单的接口自动化测试平台
查看>>
EXCEL工作表合并
查看>>
Prime Path
查看>>
ODAC(V9.5.15) 学习笔记(三)TOraSession(2)
查看>>
单纯形法
查看>>
SQL中的replace函数
查看>>
java中的类型安全问题-Type safety: Unchecked cast from Object to ...
查看>>