B -- Private Value
Time Limit:1s Memory Limit:128MByte
Submissions:513Solved:166
DESCRIPTION
The "private value" is the value that occurs, but most infrequent.
An array of integers is given, and you need print the private values of the array.
Please notice that, there might be several private values, and you need print them in increasing order.
INPUT
The first line is an integer T(1 <= T <= 4), indicating the number of test cases.For each case, the first line contains an integer n (n <= 100000).The second line contains n integers a_i (0 <= a_i <= 10^9),
OUTPUT
For each case, print all private values in increasing order in a line.
SAMPLE INPUT
271 1 2 2 3 3 355 3 2 4 1
SAMPLE OUTPUT
1 21 2 3 4 5
SOLUTION
水题,统计出现的次数最少的,排序就过了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define inf 0x6fffffff
#define LL long long
using namespace std;
int a[110000],p[110000];
int main(){
int t;
cin>>t;
while(t--){
int n,k=0,minn=inf,cur=0;
cin>>n;
for(int i=0;i<n;i++){
scanf("%d",a+i);
p[i]=0;
}
sort(a,a+n);
for(int i=0;i<n;i++){
if(a[k]==a[i]){
p[k]++;
}
else{
p[i]++;
k=i;
}
}
for(int i=0;i<n;i++)if(p[i])minn=min(minn,p[i]);
for(int i=0;i<n;i++){
if(p[i]==minn){
if(cur)cout<<" ";
else cur=1;
cout<<a[i];
}
}
cout<<endl;
}
return 0;
}