2095 find your present (2)【水题】
2015-09-06 00:10
417 查看
find your present (2)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18629 Accepted Submission(s): 7172
[align=left]Problem Description[/align]
In the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of them will be yours.Each present has a card number on it, and
your present's card number will be the one that different from all the others, and you can assume that only one number appear odd times.For example, there are 5 present, and their card numbers are 1, 2, 3, 2, 1.so your present will be the one with the card
number of 3, because 3 is the number that different from all the others.
[align=left]Input[/align]
The input file will consist of several cases.
Each case will be presented by an integer n (1<=n<1000000, and n is odd) at first. Following that, n positive integers will be given in a line, all integers will smaller than 2^31. These numbers indicate the card numbers of the presents.n = 0 ends the input.
[align=left]Output[/align]
For each case, output an integer in a line, which is the card number of your present.
[align=left]Sample Input[/align]
5
1 1 3 2 2
3
1 2 1
0
[align=left]Sample Output[/align]
3
2
HintHint
use scanf to avoid Time Limit Exceeded
比较简单的一道题,就是判断哪个数只出现一次,排好序就行查找就可以了......
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int x[1000005],n;
void slove()
{
sort(x,x+n);int cnt=0;
for(int i=0;i<n;i+=2)//遍历
{
if(x[i]!=x[i+1])//查找
{
printf("%d\n",x[i]);
return;
}
}
}
int main()
{
while(scanf("%d",&n),n)
{
memset(x,0,sizeof(x));
for(int i=0;i<n;++i)
{
scanf("%d",x+i);
}
slove();
}
return 0;
}
相关文章推荐
- nginx在linux平台下搭建
- hdu 4969 Just a Joke(数学)
- UPYUN 的 ngx_lua 应用实践 » 社区 » Ruby China
- thinkinginjava学习笔记09_内部类
- CCLabelTTF解析
- ubuntu安装rtl8723be无线网卡的驱动
- 树的一些操作
- mysql性能优化
- LVS DR模型实现
- hdu 5428 The Factor(素数筛选合数分解)
- 数据库学习2
- HDU 3376 Matrix Again(费用流)
- 转:实现OC与JS的简易交互
- 很短...道理很深
- 大三晚上的夜
- ubuntu 怎么以root权限登陆
- 数据库的学习
- J2SE_数组学习笔记
- LVS NAT模型实现
- hdu 5429 Geometric Progression(java 大数)