体测长跑计算器

时间: 1ms        内存:128M

描述:

为了方便学生查询体测成绩,烟台大学体教部邀请你编制体测长跑计算器。下图是烟台大学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 优秀

提示:

参考答案(内存最优[1092]):


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

typedef struct
{
    char name[20],xing[10];
    int Snum,m1,c;
} Sq;

int f(Sq a)
{
    int n,m;
    n=a.c;
    m=a.m1;
    if(a.xing[0]=='m')
    {
        if(m==2)
        {
            if(n<=42)
                return 110;
            else if(n>42 && n<=45)
                return 109;
            else if(n>45 && n<=48)
                return 108;
            else if(n>48 && n<=51)
                return 107;
            else if(n>51 && n<=54)
                return 106;
            else if(n>54 && n<=57)
                return 105;
            else if(n>57)
                return 104;
        }
        else if(m==3)
        {
            if(n<=1)
                return 104;
            else if(n>1 && n<=5)
                return 103;
            else if(n>5 && n<=9)
                return 102;
            else if(n>9 && n<=13)
                return 101;
            else if(n>13 && n<=17)
                return 100;
            else if(n>17 && n<=22)
                return 95;
            else if(n>22 && n<=27)
                return 90;
            else if(n>27 && n<=34)
                return 85;
            else if(n>34 && n<=42)
                return 80;
            else if(n>42 && n<=47)
                return 78;
            else if(n>47 && n<=52)
                return 76;
            else if(n>52 && n<=57)
                return 74;
            else if(n>57)
                return 72;
        }
        else if(m==4)
        {
            if(n<=2)
                return 72;
            else if(n>2 && n<=7)
                return 70;
            else if(n>7 && n<=12)
                return 68;
            else if(n>12 && n<=17)
                return 66;
            else if(n>17 && n<=22)
                return 64;
            else if(n>22 && n<=27)
                return 62;
            else if(n>27 && n<=32)
                return 60;
            else if(n>32 && n<=52)
                return 50;
            else if(n>52)
                return 40;
        }
        else if(m==5)
        {
            if(n<=12)
                return 40;
            else if(n>12 && n<=32)
                return 30;
            else if(n>32 && n<=52)
                return 20;
            else if(n>52)
                return 10;
        }
        else if(m==6)
        {
            if(n<=12)
                return 10;
            else
                return 0;
        }
        else
            return 0;
    }
    else
    {
        if(m==2)
        {
            if(n<=28)
                return 110;
            else if(n>28 && n<=33)
                return 109;
            else if(n>33 && n<=38)
                return 108;
            else if(n>38 && n<=43)
                return 107;
            else if(n>43 && n<=48)
                return 106;
            else if(n>48 && n<=53)
                return 105;
            else if(n>53 && n<=58)
                return 104;
            else if(n>58)
                return 103;

        }
        else if(m==3)
        {
            if(n<=3)
                return 103;
            else if(n>3 && n<=8)
                return 102;
            else if(n>8 && n<=13)
                return 101;
            else if(n>13 && n<=18)
                return 100;
            else if(n>18 && n<=24)
                return 95;
            else if(n>24 && n<=30)
                return 90;
            else if(n>30 && n<=37)
                return 85;
            else if(n>37 && n<=44)
                return 80;
            else if(n>44 && n<=49)
                return 78;
            else if(n>49 && n<=54)
                return 76;
            else if(n>54 && n<=59)
                return 74;
            else if(n>59)
                return 72;
        }
        else if(m==4)
        {
            if(n<=4)
                return 72;
            else if(n>4 && n<=9)
                return 70;
            else if(n>9 && n<=14)
                return 68;
            else if(n>14 && n<=19)
                return 66;
            else if(n>19 && n<=24)
                return 64;
            else if(n>24 && n<=29)
                return 62;
            else if(n>29 && n<=34)
                return 60;
            else if(n>34 && n<=44)
                return 50;
            else if(n>44 && n<=54)
                return 40;
            else if(n>54)
                return 30;
        }
        else if(m==5)
        {
            if(n<=4)
                return 30;
            else if(n>4 && n<=14)
                return 20;
            else if(n>14 && n<=24)
                return 10;
            else
                return 0;
        }
        else
            return 0;
    }
    return 0;
}

int main()
{
    int n,i,sum;
    Sq a[80];
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
        scanf("%d%s%s%d%d", &a[i].Snum,a[i].name,a[i].xing,&a[i].m1,&a[i].c);
        sum=f(a[i]);
        if(sum>=90)
            printf("%d %s %s %d 优秀\n", a[i].Snum,a[i].name,a[i].xing,sum);
        else if(sum>=80 && sum<90)
            printf("%d %s %s %d 良好\n", a[i].Snum,a[i].name,a[i].xing,sum);
        else if(sum>=60 &&sum<80)
            printf("%d %s %s %d 及格\n", a[i].Snum,a[i].name,a[i].xing,sum);
        else
            printf("%d %s %s %d 不及格\n", a[i].Snum,a[i].name,a[i].xing,sum);
    }
    return 0;
}

参考答案(时间最优[0]):

#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;
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。