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 }
  • 相关阅读:
    openvswitch 监听端口变化
    Python set() 函数
    openstack-neutron-OVS agent分析
    openvswitch ovs-appctl 使用
    python setup.py install 报错【Project namexxx was given, but was not able to be found.】
    openstack nova 创建虚机流程
    Linux kernel 模块 hello 测试
    openvswitch 流表操作
    软件测试开发之第一篇(测试文档)
    Java工具之Myeclipse程序调试
  • 原文地址:https://www.cnblogs.com/PureJava/p/10498067.html
Copyright © 2011-2022 走看看