题目描述
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.
输入
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.
输出
T lines,each line contain a integer ,the number of different color for each test.
样例输入
2
10 1 3 1 4 5 6 2 4 1 5
11
1 4 52 512 12 54 11 2 1 5 65
样例输出
6
10
这么大段英文看不懂没关系,题目意思就是统计不同数字的个数
#include <stdio.h>
int main(){
int T,n,i,j,x,count;
int a[100000];
int b[100000];
scanf("%d",&T);
while(T--){
count=0;
scanf("%d",&n);
for( x=0;x<100000;x++){
b[x]=0;
}
for(i=0;i<n;i++){
scanf("%d",&a[i]);
b[a[i]]++;
}
for(j=0;j<100000;j++){
if(b[j]>=1){
count++;
}
}
printf("%d\n",count);
}
return 0;
}
⚠️ 1.注意题目给的范围;
2.要对数组b,count 进行归0;
3. b[a[i]]++;//意为数字的出现个数。 即用数字本身作为b数组的下标。