内存:128  时间:1

题目描述

为了方便学生查询体测成绩,烟台大学体教部邀请你编制体测长跑计算器。下图是烟台大学2017年男生1000米、女生800米跑的单项评分表和加分表。评分表是根据学生长跑的时间给出得分,加分表是根据比评分表中最快时间快的时间给的加分。体测长跑计算机器是根据学生的实际长跑的时间、评分表、加分表,计算学生的长跑体测成绩。本次长跑体测器只计算大一、大二学生。

输入

第1行,n(1<=n<=50),表示后面有n个人的信息;
第2行至n+1行,每行给出一个学生的学号、姓名、性别、长跑时间(分和秒 )  。

输出

n行,每个学生的学号、姓名、性别、体测百分成绩、体测等级成绩。

样例输入

4
1229 LDian male 3 49
3244 QQian male 3 35
3215 XJie male 3 50
3247 PJie female 3 12

样例输出

1229 LDian male 76 及格
3244 QQian male 80 良好
3215 XJie male 76 及格
3247 PJie female 101 优秀

提示

代码如下

#include <iostream>
#include <cstring>
using namespace std;
struct student
{
    char no[80];
    char name[80];
    char gender[80];
    int minute;
    int second;
};
struct scoring_criteria
{
    int score;
    int minute;
    int second;
};
struct scoring_criteria sc[2][20]=  //0:male,1:female
{
    {
        {100,3,17}, {95,3,22}, {90,3,27},
        {85,3,34}, {80,3,42},
        {78,3,47}, {76,3,52}, {74,3,57},
        {72,4,2}, {70,4,7}, {68,4,12},
        {66,4,17}, {64,4,22}, {62,4,27},
        {60,4,32}, {50,4,52}, {40,5,12},
        {30,5,32}, {20,5,52}, {10,6,12}
    },
    {
        {100,3,18},{95,3,24},{90,3,30},
        {85,3,37},{80,3,44},
        {78,3,49},{76,3,54},{74,3,59},
        {72,4,4},{70,4,9},{68,4,14},
        {66,4,19},{64,4,24},{62,4,29},
        {60,4,34},{50,4,44},{40,4,54},
        {30,5,4},{20,5,14},{10,5,24}
    }
};
int addscore_table[2][10]   //加分表
{
    {-4,-8,-12,-16,-20,-23,-26,-29,-32,-35},
    {-5,-10,-15,-20,-25,-30,-35,-40,-45,-50},
};

char *str_grade[]= {"优秀","良好","及格","不及格"};

int add_score(int minute,int second,int gender)
{
    int i;
    int sec1=minute*60+second;
    int sec2=sc[gender][0].minute*60+sc[gender][0].second;
    int diff_sec=sec1-sec2;
    for(i=0; i<10; i++)
    {
        if(diff_sec>addscore_table[gender][i])
            break;
    }
    return i;
}

int score(int minute,int second,int gender)
{
    int scoring=0;
    int add_scoring=0;
    int i;
    if(minute*60+second<sc[gender][0].minute*60+sc[gender][0].second)
        add_scoring=add_score(minute,second,gender);
    for(i=0; i<20; i++)
    {
        if(minute*60+second<=sc[gender][i].minute*60+sc[gender][i].second)
        {
            scoring=sc[gender][i].score;
            break;
        }
    }
    return scoring+add_scoring;
}
char* level(int scoring)
{
    if(scoring>=90)
        return str_grade[0];
    if(scoring>=80)
        return str_grade[1];
    if(scoring>=60)
        return str_grade[2];
    return str_grade[3];
}

int main()
{
    struct student stu;
    int n,i,gender,scoring;
    char *grade;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>stu.no>>stu.name>>stu.gender>>stu.minute>>stu.second;
        cout<< stu.no<<" "<<stu.name<<" "<<stu.gender<<" ";
        gender=(strcmp(stu.gender,"male")==0)?0:1;
        scoring = score(stu.minute,stu.second,gender);
        grade = level(scoring);
        cout<< scoring<<" "<<grade<<endl;
    }
    return 0;
}

代码来源于互联网,仅供参考!