题目:
Given an array with n integers where all elements appear three times except for one. Find out the one which appears only once.
Input:
Several test cases are given, teminated by EOF.
Each test case consists of two lines. The first line gives the length of array N, and the other line describes the n elements.
Case:
4
1 1 1 3
10
1 2 3 1 2 3 1 2 3 4
result:
3
4
#include<std/bitsc++.h>
#include<cstdio>
#include<map>
using namespace std;
//map映射建立long long的计数数组
int main() {
int n;
while (scanf("%d", &n) != EOF) {
map<long long, int> mp;
while (n--) {
long long a;
scanf("%lld", &a);
mp[a]++;
}
for (map<long long, int>::iterator it = mp.begin(); it != mp.end(); it++)
if (it->second == 1) {
printf("%lld\n", it->first);
break;
}
}
return 0;
}