Source:

PAT A1041 Be Unique (20 分)

Description:

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]. 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(≤) 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

Keys:

  • 哈希映射

Code:

 /*
Data: 2019-07-21 20:19:03
Problem: PAT_A1041#Be Unique
AC: 07:07 题目大意:
找出数列中仅出现一次的数
*/ #include<cstdio>
using namespace std;
const int M=1e5+;
int lot[M],mp[M]={}; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n;
scanf("%d", &n);
for(int i=; i<n; i++)
{
scanf("%d", &lot[i]);
mp[lot[i]]++;
}
for(int i=; i<n; i++)
{
if(mp[lot[i]]==)
{
printf("%d", lot[i]);
n=;break;
}
}
if(n) printf("None"); return ;
}

PAT_A1041#Be Unique的更多相关文章

  1. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  2. [LeetCode] Minimum Unique Word Abbreviation 最短的独一无二的单词缩写

    A string such as "word" contains the following abbreviations: ["word", "1or ...

  3. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  4. [LeetCode] Unique Word Abbreviation 独特的单词缩写

    An abbreviation of a word follows the form <first letter><number><last letter>. Be ...

  5. [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  6. [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...

  7. [LeetCode] Unique Paths II 不同的路径之二

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  8. [LeetCode] Unique Paths 不同的路径

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  9. 2 Unique Binary Search Trees II_Leetcode

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...

随机推荐

  1. 实验吧关于隐写术的writeUp(二)

    0x01 Black Hole 1.下载文件后,发现打不开,放到kali中.用命令file 分析一下文件 root@trial:~/Documents# file blackhole.img blac ...

  2. send_keys报错element not interactable

    这两天要在阿里云日志中操作UI,以输入关键字搜索日志. 在send_keys时报错element not interactable. iframe 第一个问题是iframe,通过切换iframe解决: ...

  3. Apache的虚拟主机功能(基于IP、域名、端口号)

    Apache虚拟主机就是在一个Apache服务器上配置多个虚拟主机,实现一个服务器提供多站点服务,其实就是访问同一个服务器上的不同目录. 主要有三种方法: 1.通过不同的IP地址 2.通过不同的域名 ...

  4. [ERR] 153 - Got a packet bigger than 'max_allowed_packet' bytes

    异常原因: 用客户端导入数据的时候,信息包过大 ,终止了数据导入,需要修改max_allowed_packet 参数 解决方案: 1. sql语句修改( ⚠️重启服务设置会失效) 登陆mysql查看当 ...

  5. java 并发——ReentrantLock

    java 并发--ReentrantLock 简介 public class ReentrantLock implements Lock, java.io.Serializable { // 继承了 ...

  6. java 重新学习 (六)

    一.java7以后,使用带泛型的接口,类定义变量,那么调用构造器创建对象时构造器的后面不必带上泛型.List<String> list = new ArrayList()<>; ...

  7. Gitlab CI持续集成 - GitLab Runner 安装与注册

    GitLab Runner安装 需要添加gitlab官方库: # For Debian/Ubuntu/Mint curl -L https://packages.gitlab.com/install/ ...

  8. CF1223D

    CF1223D 不需要动的一定值域连续 #include<iostream> #include<cstring> #include<cstdio> #include ...

  9. wait/notify方法

    执行wait方法会释放锁,执行notify不会释放锁 package com.qf.test05.pojo; /** * @author qf * @create 2018-09-18 10:41 * ...

  10. 理解Java GC日志

    idea 在vm options处加入-XX:+PrintGCDetails,可打印GC日志. public class ReferenceCountingGC { public Object ins ...