标签:print ref second div stdio.h i++ for main span
题意:找有唯一一个出现奇数次的数
思路:利用位异或。一个数异或自己本身是0;
#include<stdio.h> int main() { int n,i,x,y; while(scanf("%d",&n)!=EOF&&n) { x=0; while(n--) { scanf("%d",&y); x^=y; } printf("%d\n",x); } return 0; }
map
#include <stdio.h> #include <algorithm> #include <map> using namespace std; int main() { int n,i,a; map<int,int>my; map<int,int>::iterator it; while(scanf("%d",&n),n) { for(i=0;i<n;i++) { scanf("%d",&a); my[a]++; } for(it=my.begin();it!=my.end();it++) { if(it->second==1) { printf("%d\n",it->first); break; } } my.clear(); } return 0; }
【HDOJ】find your present (2)(思路题)
标签:print ref second div stdio.h i++ for main span
原文地址:https://www.cnblogs.com/Kohinur/p/9071459.html