杭电2095(find your present (2))

简介: 杭电2095(find your present (2))


  • 引用块内容

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;
}


目录
相关文章
|
4月前
Strange fuction(HDU--2899)
Strange fuction(HDU--2899)
LeetCode 299. Bulls and Cows
你正在和你的朋友玩 猜数字(Bulls and Cows)游戏:你写下一个数字让你的朋友猜。每次他猜测后,你给他一个提示,告诉他有多少位数字和确切位置都猜对了(称为“Bulls”, 公牛),有多少位数字猜对了但是位置不对(称为“Cows”, 奶牛)。你的朋友将会根据提示继续猜,直到猜出秘密数字。 请写出一个根据秘密数字和朋友的猜测数返回提示的函数,用 A 表示公牛,用 B 表示奶牛。
81 0
LeetCode 299. Bulls and Cows
LeetCode 241. Different Ways to Add Parentheses
给定一个含有数字和运算符的字符串,为表达式添加括号,改变其运算优先级以求出不同的结果。你需要给出所有可能的组合的结果。有效的运算符号包含 +, - 以及 * 。
71 0
LeetCode 241. Different Ways to Add Parentheses
【hacker的错误集】DeprecationWarning: find_element_by_* commands are deprecated.
DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead。依旧是使用单词意思分析报错原因
136 0
【hacker的错误集】DeprecationWarning: find_element_by_* commands are deprecated.
|
Perl
AtCoder Beginner Contest 217 F - Make Pair (区间dp)
AtCoder Beginner Contest 217 F - Make Pair (区间dp)
112 0
|
机器学习/深度学习 Java
HDOJ 2095 find your present (2)
HDOJ 2095 find your present (2)
105 0
HDOJ 2095 find your present (2)
PAT (Advanced Level) Practice - 1068 Find More Coins(30 分)
PAT (Advanced Level) Practice - 1068 Find More Coins(30 分)
106 0
|
Web App开发 Java 数据安全/隐私保护
HDOJ(HDU) 1563 Find your present!(异或)
HDOJ(HDU) 1563 Find your present!(异或)
231 0
HDOJ 1096 A+B for Input-Output Practice (VIII)
HDOJ 1096 A+B for Input-Output Practice (VIII)
97 0
转:肉饼的自白:You&#39;ve got to find what you love
《You've got to find what you love》是乔布斯2005年在斯坦福大学毕业典礼上的演讲,当我第一次看到这个演讲视频的时候,被彻底震住了。回顾自己跌跌撞撞的人生道路,就是一个不断寻找然后坚持自己钟爱事业的过程。
1367 0