找唯一数
来源:互联网 发布:手机端如何查看源码 编辑:程序博客网 时间:2024/06/06 03:45
Problem Description
在一个表长为n的顺序表中,除一个元素之外,其余的元素都出现了两次。请找出这个仅出现一次的元素。
Input
有多组数据,每组第一行表示表长n(1<=n<=11111);第二行表示顺序表的各元素。
Output
输出这个唯一数。
Sample Input
52 2 1 3 172 1 1 3 -1 2 3
Sample Output
3-1
Hints
注意时间限制
Author
Recommend
zh
#include<iostream>
using namespace std;
int find(int * a,int N)
{
int i;
int result=0;
for(i=0;i<N;i++)
{
result ^= a[i];
}
return result;
}
int main(int argc, char* argv[])
{
int n,a[11111],i;
while(cin>>n)
{
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<find(a,n)<<endl;
}
return 0;
}
这^符号的妙用,在用一次可以找2个出现一样的数;
0 0
- 找唯一数
- 找数组中唯一出现两次的数
- (找数组中唯一出现两次的数)
- leetcode_136 Single Number-找数组中唯一的单身数
- 【C++】找数组中唯一出现两次的数
- 找唯一不同
- 微软面试题——(找数组中唯一出现两次的数) .
- 微软面试题day 7(找数组中唯一出现两次的数)
- 微软面试题--找数组中唯一出现两次的数
- 找寻单身狗(找一个数组中唯一不是一对的那个数)
- 找数
- 找数
- 找数
- 找数
- 找数
- 每日微软面试题——day 7(找数组中唯一出现两次的数)
- 每日微软面试题——day 7(找数组中唯一出现两次的数)
- 【算法】每日微软面试题——day 7(找数组中唯一出现两次的数)
- @property属性和成员变量
- 将jar 作为linux服务程序运行的方法.
- 最小生成树 Kruskal算法
- 设计模式之代理模式(Proxy)
- POJ2251 Dungeon Master
- 找唯一数
- 跨平台C++服务器程序开发 (3)Linux文件描述符
- 利用Swagger Maven Plugin生成Rest API文档
- BZOJ 1087 SCOI 互不侵犯 状态DP
- Android控件架构与view,viewgroup的测量和绘制
- 函数表达式和闭包
- 用REST获得openvswitch ovsdb的信息
- js闭包
- Please ensure that adb is correctly located at……问题解决方案