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


目录
相关文章
|
存储 小程序 JavaScript
【微信小程序】-- 生命周期(二十八)
【微信小程序】-- 生命周期(二十八)
|
11月前
|
Java 索引
Java“StringIndexOutOfBoundsException”解决
Java中的“StringIndexOutOfBoundsException”异常通常发生在尝试访问字符串中不存在的索引时。解决方法包括:1. 检查字符串长度,确保索引值在有效范围内;2. 使用条件语句避免越界访问;3. 对输入进行有效性验证。
997 6
|
XML NoSQL Java
Java单体项目和分布式项目中的锁
Java单体项目和分布式项目中的锁 Java单体项目和分布式项目中的锁
177 2
|
11月前
|
编译器
经典面试题:变量的声明和定义有什么区别
在编程领域,变量的“声明”与“定义”是经典面试题之一。声明告诉编译器一个变量的存在,但不分配内存,通常包含变量类型和名称;而定义则为变量分配内存空间,一个变量必须至少被定义一次。简而言之,声明是告知变量形式,定义则是实际创建变量并准备使用。
|
缓存 算法 自动驾驶
百度Cyber框架面试总结
百度Cyber框架面试总结
418 0
|
机器学习/深度学习 PyTorch TensorFlow
conda、anaconda、pip、pytorch、tensorflow有什么关联?
conda、anaconda、pip、pytorch、tensorflow有什么关联?
262 3
|
安全 算法 Java
java系列之~~网络通信安全 非对称加密算法的介绍说明
这篇文章介绍了非对称加密算法,包括其定义、加密解密过程、数字签名功能,以及与对称加密算法的比较,并解释了非对称加密在网络安全中的应用,特别是在公钥基础设施和信任网络中的重要性。
|
开发框架 缓存 NoSQL
基于SqlSugar的开发框架循序渐进介绍(17)-- 基于CSRedis实现缓存的处理
基于SqlSugar的开发框架循序渐进介绍(17)-- 基于CSRedis实现缓存的处理
|
设计模式 Java
【Java设计模式 面向对象设计思想】五 多用组合少用继承编程
【Java设计模式 面向对象设计思想】五 多用组合少用继承编程
386 0
【Java设计模式 面向对象设计思想】五 多用组合少用继承编程
|
数据可视化 程序员 测试技术
Gitlab上手指南(六)|如何利用vscode工具快速的解决代码冲突
相信很多用git的程序员对于git冲突都很恐惧。当你项目马上要上线,测试让你把主分支的代码合并一下,要做一个回归测试,然后你合并的时候,一堆冲突代码,直接让你头皮发麻。到底应该处理哪一个冲突,哪一段代码
4953 1

热门文章

最新文章