HackerRank

这里写图片描述

这里写图片描述

题意
给出一系列数字,输出那个出现次数为奇数次的数字

思路
用MAP标记一下,在输入的时候判断一下 之前有没有输入过,如果有,就抹掉 最后剩下的那个 就是出现次数为奇数的

或者可以用 位运算

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>

using namespace std;
typedef long long LL;

const double PI  = 3.14159265358979323846264338327;
const double E   = 2.718281828459;
const double eps = 1e-6;

const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
const int MOD  = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    map <int, int> m;
    m.clear();
    for (int i = 0; i < n; i++)
    {
        int num;
        scanf("%d", &num);
        if (m[num] == 1)
            m.erase(num);
        else
            m[num] = 1;
    }
    map <int, int>::iterator it;
    it = m.begin();
    cout << it -> first << endl;
} 
原文地址:https://www.cnblogs.com/Dup4/p/9433276.html