zoukankan      html  css  js  c++  java
  • [PAT] 1041 Be Unique (20 分)Java

    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 Wang
    11  * @Date: 2019/2/22 13:51
    12  * @Description: pattest
    13  * @Version: 1.0
    14  */
    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<String> list1 = new ArrayList<>();
    21         List<String> 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 }
  • 相关阅读:
    java设计模式概述
    Filter
    hello1 hello2 代码分析
    计划
    页面生命周期1
    Jquery
    关于DropDownList
    页面生命周期
    随机生成验证码
    关于技术
  • 原文地址:https://www.cnblogs.com/PureJava/p/10498067.html
Copyright © 2011-2022 走看看