[ZCMU OJ]1489: Problem A(哈希)

1489: Problem A

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 626  Solved: 301
[Submit][Status][Web Board]

Description

Chieh love ACM, So he likes balloons. Today he sees many balloons in the shop. And he wants to know how many different color of Balloons in the shop, because he wants to buy them to Lily.

Input

T —— the number of test cases T<=100.

For every test case, contain a integer n, the number of Balloon, next line contain n integers a1.a2....an ,the color of Balloon. 1<=n<=1000000, 1<=ai<=100000.

Output

T lines,each line contain a integer ,the number of different color for each test.

Sample Input

2 10 1 3 1 4 5 6 2 4 1 5 11 1 4 52 512 12 54 11 2 1 5 65

Sample Output

6 10
这道题的意思简单来说就是给一堆气球问有几种颜色。
典型的哈希。上ac代码。
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int T;
	long long n,i;
	long long x,cnt;
	int a[100000];
	
	memset(a,0,sizeof(a));
	
	while(cin>>T)
	{
		while(T--)
		{
			cin>>n;
			
			cnt=0;
			memset(a,0,sizeof(a));
			
			for(i=0;i<n;i++)
			{
				cin>>x;
				
				a[x]++;
				if(a[x]==1)
				cnt++;
			}
			cout<<cnt<<endl;
		}
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值