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 17Sample Output 1:
31Sample Input 2:
5 888 666 666 888 888Sample Output 2:
None
题目开始我也没全部看懂,但是知道了他要求什么,先输入一个正整数N,输入N个数字,找出第一个独一无二的数字,倘如没有,则输出None;
关键问题:找出独一无二的点,
输出首个这样的点
最后判断是否不存在这样的点。
思路 :1、建立一个Hash表,因为数字的大小范围时[1,10000],那我们就可以设置一个比10000大的数组table[],初始为0,当得到一个数字num,则table[num]++; //解决了第一个问题;
2、建立一个数组num[],用来存放我输入的内容,得到其顺序,按照num[]的顺序,查找table[]的个数是否为1。//解决第二个问题
3、最后根据循环判断,//解决问题3.
代码如下:
#include <iostream> #include <cstdio> using namespace std; int main() { int number[100010]; int table[10010]={0}; int n,i; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&number[i]); table[number[i]]++; } for(i=0;i<n;i++) { if(table[number[i]]==1) { printf("%d",number[i]); break; } } if(i==n) printf("None"); return 0; }
lottery 彩票
顺便翻译一波吧,哈哈:
对于火星上的人来说,独一无二是如此的重要,以至于他们的彩票以一个独一无二的方式被设计。赢彩票的方式很简单:每个赌注是[1,10000]上的一个数字,第一个下注在了一个独一无二的数字上的人获胜。比如,有7个人下的赌注分别是5 31 5 88 67 88 17,那么第二个赌31 的人获胜。