lwjppz 2018-11-27 02:28 采纳率: 54.5%
浏览 382

这题不会做啊?求解答,求助

图片说明

  • 写回答

1条回答

  • mkchiny 2018-11-28 10:16
    关注
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define MAX_ITEM_NUM 10000
    #define MAX_VALUE 10000
    #define MAX(a, b) ((a) > (b) ? (a) : (b))
    
    int main(void)
    {
        int item_num = 0;
        int count_each_num[MAX_VALUE] = {0};
        int index = 0;
        int value = 0;
        int max_value = 0;
    
        scanf("%d", &item_num);
        if(item_num < 1 || item_num > MAX_ITEM_NUM)
        {
            printf("please input number in 1 to %d !!!", MAX_ITEM_NUM);
            return -1;
        }
    
        //memset(count_each_num, 0, sizeof(count_each_num));
        for(index = 0; index < item_num; index++)
        {
            scanf("%d", &value);
            if(value >= MAX_VALUE)
            {
                printf("each number must less than %d !!!", MAX_VALUE);
                return -2;
            }
            max_value = MAX(value, max_value);
            count_each_num[value]++;
        }
    
        for(index = 0; index <= max_value; index++)
        {
            printf("%d:%d\n", index, count_each_num[index]);
        }
    
        return 0;
    }
    
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!