1141
来源:互联网 发布:新日铁住金软件 编辑:程序博客网 时间:2024/04/29 01:02
题目描述
There is a sequence S consisting of N numbers, where N is an odd number. All numbers in this sequence appear even number times, except one showing up odd number times, which we call unique number. For example, in the sequence {3, 4, 4, 9, 3, 5, 3, 3, 9}, the number 5 is the unique number. Now you are required to work out the unique number for given sequence.
输入
Input file consists of several cases.The first line of each case contains a number N. Each of the next N lines contains only one number Si. We guarantee that the number N is no more than 100,000, and Si is no more than 2^31.
输出
For each case, just return the unique number in one line.
样例输入
9344935339
样例输出
5
提示
Try O(n) algorithm.
来源
2012.03
#include<stdio.h>#include<string.h>int comp(const void *a, const void *b){ return *(int *)a - *(int *)b;}int main(){ int i,n; while(scanf("%d",&n)!=EOF) { int num=0; int a[n],m; for(i=0;i<n;i++) scanf("%ld",&a[i]); qsort(a,n,sizeof(a[0]),comp);for (i=0;i<n;i++){if (i==0||a[i]!=a[i-1]) {//第一个和每一个新出现的第一个if (num%2) {printf("%d\n",a[i-1]);break;}num=1;//每一个新出现数的第一个记为1}else num++;}} return 0;}
0 0
- 1141
- 1141
- 1141
- 1141
- LIGHT OJ 1141 1141
- POJ 1141
- POJ 1141
- poj 1141
- POJ 1141
- poj 1141
- poj 1141
- POJ 1141
- hdu 1141
- poj 1141
- POJ 1141
- POJ 1141
- URAL 1141
- poj 1141
- mybatis一对一关联关系
- android 5.0机上INSTALL_FAILED_DUPLICATE_PERMISSION错误的解决办法
- 好用的工具集合
- linux怎么查看连接的创建时间
- IDEA建maven项目,默认创建src目录
- 1141
- 自定义Toast
- 【git】Your branch is up-to-date 和 Everything up-to-date
- 十款精心挑选的在线 CSS3 代码生成工具
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- android selector标签详解
- java多线程
- 排序算法(六) - 总结篇
- DataGridView.BorderStyle 属性