Find a number HNUST OJ 1517 (位运算 判断一列数字中出现的唯一一个奇数数字)
2017-12-08 11:30
267 查看
题目描述
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;
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); } }
相关文章推荐
- Find a number HNUST OJ 1517 (位运算 判断一列数字中出现的唯一一个奇数数字)
- Find a number HNUST OJ 1517 (位运算 判断一列数字中出现的唯一一个奇数数字)
- Find a number HNUST OJ 1517 (位运算 判断一列数字中出现的唯一一个奇数数字)
- Find a number HNUST OJ 1517 (位运算 判断一列数字中出现的唯一一个奇数数字)
- Find a number HNUST OJ 1517 (位运算 判断一列数字中出现的唯一一个奇数数字)
- Find a number HNUST OJ 1517 (位运算 判断一列数字中出现的唯一一个奇数数字)
- java经典算法_032判断一个数字是奇数还是偶数
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的,找出这个数字(使用位运算)
- 九度OJ 1256:找出两个只出现了一次的数字 (位运算)
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的。 请找出这个数字。(使用位运算)
- 一组数据中只有一个数字出现了一次。 其他所有数字都是成对出现的。请找出这个数字。(使用位运算)
- 判断一个数字是奇数还是偶数
- 3.有一个整形数组,只有一个数字出现了一次,请编写程序判断这个数字(大概题目就是这样的,记不太清了)
- 输入一个数字判断为偶数还是奇数用switch
- 每日一算法6--判断一个数字是奇数还是偶数
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的。请找出这个数字。(使用位运算)
- P51.19(请输入一个正整数n,判断其中各位数字是否奇偶交替出现。)
- Java作业:输入一个数字判断他是奇数还是偶数
- 现在有N个数字,其中只有一个数字出现的次数是奇数次,如何找到这个数字?
- 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的,求这个数字。(使用位运算)