Time Limit:1s Memory Limit:128MByte
Submissions:526Solved:174
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.
原题链接:http://www.ifrog.cc/acm/problem/1057
题意:输出一个序列中出现次数最少的元素,数组可能会超时,类似于桶排序的方法估计也会超时,我用map就不用考虑那么多了。
AC代码:
/**
* 行有余力,则来刷题!
* 博客链接:http://blog.youkuaiyun.com/hurmishine
*
*/
#include <iostream>
#include <map>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
map<int,int>mp;
mp.clear();
int x;
for(int i=0; i<n; i++)
{
cin>>x;
mp[x]++;
}
map<int,int>::iterator iter;
int minn=1e9;
for(iter=mp.begin(); iter!=mp.end(); iter++)
{
if(iter->second<minn)
minn=iter->second;
}
bool first=true;
for(iter=mp.begin(); iter!=mp.end(); iter++)
{
if(iter->second==minn)
{
if(!first)
cout<<" "<<iter->first;
else
{
first=false;
cout<<iter->first;
}
}
}
cout<<endl;
}
return 0;
}