【id:396】【10分】G. 【课程设计】Analysis

题目原文

题目描述

输入一串成绩(正整数),输出GPA统计结果。

输入

若干个整数

输出

由高到低输出统计结果。

样例

输入样例1

40 50 60 -1 60 100

输出样例1

A+: 1
D: 2
F: 2

提示

需要过滤掉不合法输入:成绩不在0~100区间内的。

AC代码

#include <stdio.h>

char GPA[10][5] = {{"A+"}, {"A"}, {"B+"}, {"B"}, {"C+"}, {"C"}, {"D"}, {"F"}};
int GPA_cnt[10] = {0};

int main()
{
    int score;
    while (~scanf("%d", &score))
    {
        if (score < 0 || score > 100)
            continue;

        if (score >= 93)
            GPA_cnt[0]++;
        else if (score >= 85)
            GPA_cnt[1]++;
        else if (score >= 80)
            GPA_cnt[2]++;
        else if (score >= 75)
            GPA_cnt[3]++;
        else if (score >= 70)
            GPA_cnt[4]++;
        else if (score >= 65)
            GPA_cnt[5]++;
        else if (score >= 60)
            GPA_cnt[6]++;
        else
            GPA_cnt[7]++;
    }

    for (int i = 0; i < 8; i++)
        if (GPA_cnt[i])
            printf("%s: %d\n", GPA[i], GPA_cnt[i]);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值