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;
}