Find a number HNUST OJ 1517 (位运算 判断一列数字中出现的唯一一个奇数数字)
来源:互联网 发布:手机修改淘宝店铺名称 编辑:程序博客网 时间:2024/06/05 21:56
题目描述
Find a number which is repeated odd times, then You should output the number.
Example 1:
if input is:12 12 12 12 15
then output is: 15
Example 2:
if input is:12 13 12 13 18 12 13 13 18
then output is: 12
输入
First line contains a positive integer N < 500000 ,then, N positive integers follow (delimited with space) each less than 1 000 000.
输出
In input sequence only one number X is repeated odd times. Others have even number of occurrences. You should output X.
样例输入
9
3 1 2 2 17 1 3 17 3
样例输出
3
提示
Find a number which is repeated odd times, then You should output the number.
Example 1:
if input is:12 12 12 12 15
then output is: 15
Example 2:
if input is:12 13 12 13 18 12 13 13 18
then output is: 12
输入
First line contains a positive integer N < 500000 ,then, N positive integers follow (delimited with space) each less than 1 000 000.
输出
In input sequence only one number X is repeated odd times. Others have even number of occurrences. You should output X.
样例输入
9
3 1 2 2 17 1 3 17 3
样例输出
3
提示
If you can avoid error "Memory Limit Exceed", this problem will be a very simple problem.
思路:位运算中的异或运算符,2个数字异或则为0;
#include<iostream>#include<cstdio>using namespace std;int main(){ int n; while(scanf("%d",&n)==1) { int sum=0,num; while(n--) { scanf("%d",&num); sum=sum^num; } printf("%d\n",sum); }}
阅读全文
0 0
- Find a number HNUST OJ 1517 (位运算 判断一列数字中出现的唯一一个奇数数字)
- 九度OJ 1351:数组中只出现一次的数字 (位运算)
- 学习笔记——利用位运算求数组中只出现一次或奇数次的数字
- LeetCode OJ 之 Single Number (唯一的数字)
- 【C语言】一组数据中只有一个数字出现了一次。 其他所有数字都是成对出现的。请找出这个数字。(使用位运算)
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的。请找出这个数字。(使用位运算)
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的。请找出这个数字。(使用位运算)
- 一组数据中只有一个数字出现了一次。 其他所有数字都是成对出现的。请找出这个数字。(使用位运算)
- 一组数据中只有一个数字出现了一次。 其他所有数字都是成对出现的。请找出这个数字。(使用位运算)
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的,找出这个数字(使用位运算)
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的。 请找出这个数字。(使用位运算)
- 编程实现: 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的。 请找出这个数字。(使用位运算)
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的,求这个数字。(使用位运算)
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的。 请找出这个数字。(使用位运算)
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的。找出这个数字。(使用位运算)
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的。 请找出这个数字。(使用位运算)
- 位运算-Single Number II(给定一个数组,除了一个数字出现一次,其他都出现三次,求出现一次的数)
- Java 判断数组中唯一一个不重复的数字,其它数字重复两次
- LINUX进程和线程_通信以及退出方式
- 第一篇博客
- 【Spring Cloud】--Spring boot入门实例
- 算法导论:c++选择算法
- 在eclipse中修改非maven项目web工程名称
- Find a number HNUST OJ 1517 (位运算 判断一列数字中出现的唯一一个奇数数字)
- 百度地图显示/隐藏放大缩小按钮
- c++练习-构造学生类
- poj2528——Mayor's posters
- 在celipse上搭建ssm框架,并整合freemarker
- FFmpeg .sh文件命令解释
- onSaveInstanceState方法会在什么时候被执行
- oracle reports报表打开相关问题
- 切片