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. Java对象toString()方法

    对象的字符串表示以可读格式包含有关对象状态的信息.Object类的toString()方法表示字符串中类的对象.Object类提供了toString()方法的默认实现. 它返回一个以下格式的字符串: ...

  2. 转 JMeter基础之--元件的作用域与执行顺序

    前面有介绍过jmeter的元件类别,对于新手来说,jmeter的元件是还是不少的,如果我们按照每一个元件的每一个参数的含义去学习,无疑会降低学习性能测试的热情,就算我们熟悉了所有元件以及元件上的参数了 ...

  3. 转 mysql查询结果输出到文件

    mysql查询结果输出到文件   mysql查询结果导出/输出/写入到文件 方法一:直接执行命令:mysql> select count(1) from table  into outfile ...

  4. 【目录】ASP.NET Core 基础教程

    ASP.NET Core 基础教程 ASP.NET Core 基础教程 ASP.NET Core 简介 ASP.NET Core Windows 环境配置 ASP.NET Core macOS 环境配 ...

  5. python--知识小结和集合

    知识小结 一. = 表示赋值 ==表示比较值的大小 is 比较内存地址 二. 数字小数据池:在-5~256之内,id在电脑里是一样的 字符串id一样要求: ①:不能有特殊字符 ②:s(一个单字符)*2 ...

  6. 2018年分享的Spring Cloud 2.x系列文章

    还有几个小时2018年就要过去了,盘点一下小编从做做公众号以来发送了273篇文章,其中包含原创文章90篇,虽然原创的有点少,但是2019年小编将一如既往给大家分享跟多的干货,分享工作中的经验,让大家在 ...

  7. windows线程函数必须为全局函数或者静态函数(转)

    调用CreateThread(...)创建线程时要指定所创建线程的入口函数,此入口函数只能是全局函数或者类的静态成员函数. 全局函数很容易理解,但如果是类的成员函数则必须是静态成员函数,为何, 因为类 ...

  8. 使用navigator.userAgent来判断浏览器类型

    var br=navigator.userAgent.toLowerCase(); var browserVer=(br.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ...

  9. delphi和C# 保存exe文件到数据库

    Delphi: procedure TForm1.Button1Click(Sender: TObject); var strSQL, sfilename: string; MStream: TMem ...

  10. 08-01-json-loggin-模块

    复习 ''' ATM: -- start.py BASE_DIR = os.path.dirname(__file__) sys.path.append(BASE_DIR) -- conf -- li ...