zcmu oj 1489:Problem A(数气球)

题目描述

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数组的下标。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值