find your present (2) hdoj 2095

/*
author:谦智
find your present (2)  hdoj 2095
法一:用暴力
法二:用map
法三:
符号是^.
异或是个位运算符号,具体是怎么操作的请百度,这里有个特性使得他能产生一种巧方法
a^a=0 
0^c=c

看到上面这个式子是否你懂了呢?
没错,例如样例
5
1 1 3 2 2
如果我们用异或运算计算就是
1^1^3^2^2

由于1^1=0 2^2=0,那么就只剩下了唯一的一个3了。
如果有3个3,那么前面偶数个3由于3^3=0,势必也会只留下一个孤单的3.

那么答案就只能是那个多余的数字了。 


*/

//#include<iostream>
//#include<cstdio>
//using namespace std;
//int main() {
//  int n;
//  while (scanf("%d",&n),n) {
//    int ans = 0;
//    for (int i = 0; i < n; i++) {
//      int x;
//      scanf("%d",&x);
//      ans ^= x;
//    }
//    printf("%d\n",ans);
//  }
//}



//#include<iostream>
//using namespace std;
//int main() {
//  int n;
//  while (cin >> n, n) {
//    int ans = 0;
//    for (int i = 0; i < n; i++) {
//      int x;
//      cin >> x;
//      ans ^= x;
//    }
//    cout << ans << endl;
//  }
//}




//map 改题设定为c的输入输出 
#include<iostream>
#include<map>
#include<cstdio>
using namespace std;
int main() {
  int n;
  while (scanf("%d",&n),n) {
    map<int,int> Map;
    for (int i = 0; i < n; i++) {
      int x;
      scanf("%d",&x);
      Map[x]++;
    }
    map<int,int>::iterator it = Map.begin();
    for (; it != Map.end(); it++) {
      if (it->second%2) {
        printf("%d\n",it->first);
        break;
      }
    }
  }
}

 

posted @ 2018-03-16 20:32  扫地の小沙弥  阅读(137)  评论(0编辑  收藏  举报