zoukankan      html  css  js  c++  java
  • PAT 甲级 1041 Be Unique (20 分)

    1041 Be Unique (20 分)

    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 #include<iostream>
     2 #include<map>
     3 
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int N, temp, index = 1, min = 999999;
     9     map<int, int> m;
    10 
    11     cin >> N;
    12 
    13     for (int i = 0; i<N; ++i)
    14     {
    15         cin >> temp;
    16 
    17         if (m.find(temp) == m.end())
    18             m.insert(pair<int, int>(temp, index++));
    19         else
    20             m[temp] = 0;
    21     }
    22 
    23     map<int, int>::iterator begin = m.begin(), end = m.end(), i, minIndex;
    24 
    25     for (i = begin; i != end; ++i)
    26     {
    27         if (i->second>0 && i->second<min)
    28         {
    29             min = i->second;
    30             minIndex = i;
    31         }
    32     }
    33 
    34     if (min == 999999)
    35         cout << "None" << endl;
    36     else
    37         cout << minIndex->first << endl;
    38 }
  • 相关阅读:
    BZOJ 3160 万径人踪灭
    BZOJ 2160 拉拉队排练
    模板 manacher算法
    [Tjoi2016&Heoi2016]求和
    [HZOI 2015]疯狂的机器人
    [BZOJ3456]城市规划
    BZOJ 4372 烁烁的游戏
    洛谷3794 签到题IV
    BZOJ 3730 震波
    BZOJ 4916 神犇和蒟蒻
  • 原文地址:https://www.cnblogs.com/cdp1591652208/p/10229558.html
Copyright © 2011-2022 走看看