【id:394】【10分】A. 【课程设计】 Init

题目原文

题目描述

你需要将一系列的学生期末考试信息进行存储(学生人数不会超过100)。每个学生的信息包括:

姓名(由 first name 和last name 两部分组成,例如Jingyu LI,first_name = “Jingyu” last_name = “LI”) ;
学号(12 位数字组成,开头4位为2022、2021、2020);
C语言成绩(一个大于等于零的整数);
重修信息(学号 2022…为否,其余为是);

GPA等级(A+, A, B+, B, C+, C, D, F )。
A+: 100-93;
A: 92-85;
B+: 84-80;
B: 79-75;
C+:74-70;
C: 69-65;
D: 64-60;
F: <60.

其中,姓名,学号,成绩为输入数据,其余数据需要你计算。

另外,学号不符合规定的数据需要删除掉。

输入

一系列 名、姓、学号、成绩

输出

名、姓、学号、成绩、重修信息、GPA等级

样例

输入样例1

Jingyu LI 202200000000 85
Jy LEE 202200100000 89
Jxxxyx Leeeee 202000100000 100
Geinyu LEE 20220000 89
Jingyu11 LI 202200000001 85

输出样例1

Name_f Name_l stu_id score retake GPA rank
Jingyu LI 202200000000 85 0 A
Jy LEE 202200100000 89 0 A
Jxxxyx Leeeee 202000100000 100 1 A+
Jingyu11 LI 202200000001 85 0 A

提示

Geinyu LEE 20210000 89 不合法,需删掉。

AC代码

#include <stdio.h>
#include <string.h>

struct Information
{
    char first_name[20];
    char last_name[20];
    char id[20];
    int score;
    int retake;
    char GPA[5];

} stu[110];

void get_gpa(int i)
{
    if (stu[i].score >= 93)
        strcpy(stu[i].GPA, "A+");
    else if (stu[i].score >= 85)
        strcpy(stu[i].GPA, "A");
    else if (stu[i].score >= 80)
        strcpy(stu[i].GPA, "B+");
    else if (stu[i].score >= 75)
        strcpy(stu[i].GPA, "B");
    else if (stu[i].score >= 70)
        strcpy(stu[i].GPA, "C+");
    else if (stu[i].score >= 65)
        strcpy(stu[i].GPA, "C");
    else if (stu[i].score >= 60)
        strcpy(stu[i].GPA, "D");
    else
        strcpy(stu[i].GPA, "F");
}

int main()
{
    printf("Name_f Name_l stu_id score retake GPA rank\n");

    for (int i = 0; ~scanf("%s%s%s%d", stu[i].first_name, stu[i].last_name, stu[i].id, &stu[i].score); i++)
    {
        if (strlen(stu[i].id) != 12)
        {
            i--;
            continue;
        }

        get_gpa(i);

        if (memcmp(stu[i].id, "2022", 4) != 0)
            stu[i].retake = 1;

        printf("%s %s %s %d %d %s\n", stu[i].first_name, stu[i].last_name, stu[i].id, stu[i].score, stu[i].retake, stu[i].GPA);
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值