码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 1041 Be Unique


    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,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

    solution

    找首个只出现了一次的数字,若无则为None。
    和前面几题稍有不同,不是直接找出现次数。加了需要首次出现的条件。

    #include 
    int main(){
    	int hash[10001] = {0}, n, a[100005];
    	scanf("%d", &n);
    	for(int i = 1; i <= n; i++){
    		scanf("%d", a + i);
    		hash[a[i]]++;
    	}
    	for(int i = 1; i <= n; i++){
    		if(hash[a[i]] == 1){
    			printf("%d", a[i]);
    			return 0;
    		}
    	}
    	printf("None");
    	return 0;
    } 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
  • 相关阅读:
    arcgis中编码方式改变引起的shp文件乱码、字符截断问题处理
    基于Skywalking的全链路跟踪实现
    初识OpenGL (-)VAO顶点数组对象
    万兆光模块对网络性能的提升有多大?
    关于时间复杂度的一些新认识
    JS 运行机制最全面的一次梳理
    【C++】stack和queue
    Golang操作sqlite3数据库教程
    输入 3 个数 a、b、c, 求这 3 个数的最小公倍数
    《论语译注》笔记
  • 原文地址:https://blog.csdn.net/Moliay/article/details/133387951
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号