Description
找出出现奇数次的数
Input
There are multiple test cases.
Each test case contains two lines. The first line is an integer N, 1 <= N <= 10001, and N % 2 = 1. The second line contains N integers, separated by spaces.
Input is terminated by EOF.
Output
For each test case, output a line of an integer, which should be the lovely number.
Sample Input
3
1 2 1
57 7 7 7 3
7
2 2 4 4 4 2 2
Sample Output
2
3
4
c++找出数组中出现奇数次的数
答案:1 悬赏:10
解决时间 2021-02-22 05:21
- 提问者网友:℡她的他i☆
- 2021-02-21 22:53
最佳答案
- 二级知识专家网友:我们只是兮以城空
- 2021-02-21 23:03
#include
int main()
{
int n,ans,tmp;
while(scanf("%d",&n)!=EOF){
n--;
scanf("%d",&tmp);
ans=tmp;
while(n--){
scanf("%d",&tmp);
ans=ans^tmp;
}
printf("%d\n",ans);
}
return 0;
}参考这段代码哈,欢迎交流。满意请采纳。
int main()
{
int n,ans,tmp;
while(scanf("%d",&n)!=EOF){
n--;
scanf("%d",&tmp);
ans=tmp;
while(n--){
scanf("%d",&tmp);
ans=ans^tmp;
}
printf("%d\n",ans);
}
return 0;
}参考这段代码哈,欢迎交流。满意请采纳。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯