首页 > 其他分享 >杭电2095(find your present (2))

杭电2095(find your present (2))

时间:2023-02-05 21:07:27浏览次数:68  
标签:2095 max number find 杭电 will card your present


​这里写链接内容​​>

  • 引用块内容

Problem Description

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.

Input

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.

Output

For each case, output an integer in a line, which is the card number of your present.

Sample Input

5
1 1 3 2 2
3
1 2 1
0

Sample Output

3
2

#include<stdio.h>
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
int x=0,y;
while(n--)
{
scanf("%d",&y);
x=x^y;
}
printf("%d\n",x);
}
return 0;
}

题目总结:
此题题意不明 如果按上面代码的话
意思是找出数据中特殊的数也即是出现次数最少的数据 这里用到了异或

​​异或详解​​

#include<stdio.h>
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
int m,max=-0x3f3f3f3f;
while(n--)
{
scanf("%d",&m);
if(m>max)
max=m;
}
printf("%d\n",max);
}
return 0;
}

这个是找出数据中最大值即可这样也可以 ac 的。

​最大值的设置技巧 max=-0x3f3f3f3f​


标签:2095,max,number,find,杭电,will,card,your,present
From: https://blog.51cto.com/u_14235050/6038399

相关文章