Lonlife 1057 Private Value

1057 - Private Value

Time Limit:1s Memory Limit:128MByte

Submissions:500Solved:162

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<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int t,i,j,k,l,n,m,a[100010],b[100010];
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		m=a[0];
		int minn=1000100;
		k=1;
		l=1;
		for(i=1;i<n;i++)
		{
			if(a[i]==m)
			{
				k++;
			}
			else
			{
				
			    if(k<minn)
			    {
			    	memset(b,0,sizeof(b));
			    	minn=k;
			    	b[0]=m;
			    	l=1;
				}
				else if(k==minn)
				{
					b[l++]=a[i-1];
						
				}
				m=a[i];
				k=1;
			}
		}
		if(k==minn)
		{
			b[l++]=m;
		}
		sort(b,b+l);
		for(i=0;i<l-1;i++)
		{
			printf("%d ",b[i]);
		}
		printf("%d\n",b[i]);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值