2020年MOOCC语言程序设计精髓第十二周编程题测试

1计算时间差V2.0
题目内容:
用结构体定义时钟类型,编程从键盘任意输入两个时间(例如4时55分和1时25分),计算并输出这两个时间之间的间隔。要求不输出时间差的负号。结构体类型定义如下:
typedef struct clock
{
int hour;
int minute;
int second;
} CLOCK;
函数原型: CLOCK CalculateTime(CLOCK t1, CLOCK t2);
函数功能:计算并返回两个时间t1和t2之间的差
程序运行结果示例1:
Input time one:(hour,minute):4,55↙
Input time two: (hour,minute):1,25↙
3hour,30minute
程序运行结果示例2:
Input time one:(hour,minute):1,33↙
Input time two: (hour,minute):5,21↙
3hour,48minute
输入提示: “Input time one:(hour,minute):”
“Input time two: (hour,minute):”
输入格式: “%d,%d”
输出格式:"%dhour,%dminute\n"

#include 

typedef struct clock
{
    int hour;
    int minute;
    int second;
} CLOCK;

CLOCK CalculateTime(CLOCK t1,CLOCK t2){
    CLOCK c,c1,c2;
    if(t1.hour>t2.hour){
        c1=t1;
        c2=t2;
    }
    else if(t1.hour==t2.hour&&t1.minute>t2.minute){
        c1=t1;
        c2=t2;
    }
    else{
        c1=t2;
        c2=t1;
    }
    if(c1.minute<c2.minute){
        c.minute=60+c1.minute-c2.minute;
        c1.hour-=1;
    }
    else
        c.minute=c1.minute-c2.minute;
    c.hour=c1.hour-c2.hour;
    return c;
}

int main(){
    int i;
    CLOCK t1,t2,t;
    printf("Input time one:(hour,minute):");
    scanf("%d,%d",&t1.hour,&t1.minute);
    printf("Input time two: (hour,minute):");
    scanf("%d,%d",&t2.hour,&t2.minute);
    t=CalculateTime(t1,t2);
    printf("%dhour,%dminute\n",t.hour,t.minute);
}

2奖学金发放
题目内容:
某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,每项奖学金获取的条件分别如下:

  1. 院士奖学金:期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生每人均可获得8000元;
  2. 五四奖学金:期末平均成绩高于85分(>85),并且班级评议成绩高于80分(>80)的学生每人均可获得4000元;
  3. 成绩优秀奖:期末平均成绩高于90分(>90)的学生每人均可获得2000元;
  4. 西部奖学金:期末平均成绩高于85分(>85)的西部省份学生每人均可获得1000元;
  5. 班级贡献奖:班级评议成绩高于80分(>80)的学生干部每人均可获得850元;

只要符合上述条件就可获得相应的奖项,每项奖学金的获奖人数没有限制,每名学生也可以同时获得多项奖学金。例如姚明的期末平均成绩是87分,班级评议成绩82分,同时他还是一位学生干部,那么他可以同时获得五四奖学金和班级贡献奖,奖金总数是4850元。
现在给出若干学生的相关数据(假设总有同学能满足获得奖学金的条件),请编程计算哪些同学获得的奖金总数最高。
结构体类型定义如下:

typedef struct winners
 {
     char name[20];
     int finalScore;
     int classScore;
     char work;
     char west;
     int paper;
     int scholarship;
 } WIN;

函数原型:void Addup(WIN stu[], int n);
函数原型:int FindMax(WIN student[], int n);
程序运行结果示例:
Input n:4↙
Input name:YaoMing↙
Input final score:87↙
Input class score:82↙
Class cadre or not?(Y/N):Y↙
Students from the West or not?(Y/N):N↙
Input the number of published papers:0↙
name:YaoMing,scholarship:4850
Input name:ChenRuiyi↙
Input final score:88↙
Input class score:78↙
Class cadre or not?(Y/N):N↙
Students from the West or not?(Y/N):Y↙
Input the number of published papers:1↙
name:ChenRuiyi,scholarship:9000
Input name:LiXin↙
Input final score:92↙
Input class score:88↙
Class cadre or not?(Y/N):N↙
Students from the West or not?(Y/N):N↙
Input the number of published papers:0↙
name:LiXin,scholarship:6000
Input name:ZhangQin↙
Input final score:83↙
Input class score:87↙
Class cadre or not?(Y/N):Y↙
Students from the West or not?(Y/N):N↙
Input the number of published papers:1↙
name:ZhangQin,scholarship:8850
ChenRuiyi get the highest scholarship 9000

输入学生人数提示:“Input n:”
输入学生姓名提示:“Input name:”
输入学生期末平均成绩提示:“Input final score:”
输入学生班级评议成绩提示:“Input class score:”
输入是否为学生干部提示:“Class cadre or not?(Y/N):”
输入是否为西部学生提示:“Students from the West or not?(Y/N):”
输入发表文章数量提示:“Input the number of published papers:”
输入格式:

输入学生人数:"%d"
输入学生姓名:"%s"
输入学生成绩:"%d"
输入是否为学生干部:" %c" (注意:%c前面有一个空格)
输入是否为西部学生:" %c" (注意:%c前面有一个空格)
输入发表文章数量: "%d"

输出格式:

 输出学生获得的奖学金:  "name:%s,scholarship:%d\n"
 输出获得奖学金总数最高的学生:"%s get the highest scholarship %d\n"
#include 

typedef struct winners
{
    char name[20];
    int finalScore;
    int classScore;
    char work;
    char west;
    int paper;
    int scholarship;
} WIN;

int Scholarship(WIN stu){
    int scholarship=0;
    if(stu.finalScore>80&&stu.paper>=1)
        scholarship+=8000;
    if(stu.finalScore>85&&stu.classScore>80)
        scholarship+=4000;
    if(stu.finalScore>90)
        scholarship+=2000;
    if(stu.finalScore>85&&stu.west=='Y')
        scholarship+=1000;
    if(stu.classScore>80&&stu.work=='Y')
        scholarship+=850;
    return scholarship;
}

void Addup(WIN stu[], int n){
    int i;
    for(i=0;i<n;i++){
        printf("Input name:");
        scanf("%s",stu[i].name);
        printf("Input final score:");
        scanf("%d",&stu[i].finalScore);
        printf("Input class score:");
        scanf("%d",&stu[i].classScore);
        printf("Class cadre or not?(Y/N):");
        scanf(" %c",&stu[i].work);
        printf("Students from the West or not?(Y/N):");
        scanf(" %c",&stu[i].west);
        printf("Input the number of published papers:");
        scanf("%d",&stu[i].paper);
        stu[i].scholarship=Scholarship(stu[i]);
        printf("name:%s,scholarship:%d\n",stu[i].name,stu[i].scholarship);
    }
}

int FindMax(WIN student[], int n){
    int max=0,i,num;
    for(i=0;i<n;i++){
        if(student[i].scholarship>max){
            max=student[i].scholarship;
            num=i;
        }
    }
    printf("%s get the highest scholarship %d\n",student[num].name,student[num].scholarship);
    return 0;
}

int main(){
    int i,n;
    printf("Input n:");
    scanf("%d",&n);
    WIN *stu;
    stu=(WIN *)malloc(n*sizeof(WIN));
    Addup(stu,n);
    FindMax(stu,n);
    return 0;
}

3评选最牛群主v1.0
题目内容:
现在要评选最牛群主,已知有3名最牛群主的候选人(分别是tom,jack和rose),有不超过1000人参与投票,最后要通过投票评选出一名最牛群主,从键盘输入每位参与投票的人的投票结果,即其投票的候选人的名字,请你编程统计并输出每位候选人的得票数,以及得票数最多的候选人的名字。候选人的名字中间不允许出现空格,并且必须小写。若候选人名字输入错误,则按废票处理。
2020年MOOCC语言程序设计精髓第十二周编程题测试_第1张图片
提示输入候选人数量:“Input the number of electorates:”
提示输入候选人: “Input vote %d:”
输入格式:

输入候选人数量:"%d"
输入候选人姓名:"%s"   

输出格式:

输出候选人得票数:"%s:%d\n"     
输出票数最多的候选人姓名:"%s wins\n"

输出评选结果提示信息:“Election results:\n”

#include 
#include 
#define MAX 3
#define NAME 10

char candidate[MAX][NAME]={"tom","jack","rose"};

int main(){
    int i,j,n,max=0;
    int vote[MAX]={0};
    char name[NAME];
    printf("Input the number of electorates:");
    scanf("%d",&n);
    for(i=0;i<n;i++){
        printf("Input vote %d:",i+1);
        scanf("%s",name);
        for(j=0;j<MAX;j++){
            if(strcmp(name,candidate[j])==0)
                vote[j]++;
        }
    }
    printf("Election results:\n");
    for(i=0;i<MAX;i++){
        if(vote[i]>vote[max])
            max=i;
        printf("%s:%d\n",candidate[i],vote[i]);
    }
    printf("%s wins\n",candidate[max]);
    return 0;
}

4星期判断
题目内容:请输入星期几的第一个字母(不区分大小写)来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母(小写),否则输出“data error”。
程序运行结果示例1:
please input the first letter of someday:
S↙
please input second letter:
u↙
sunday
程序运行结果示例2:
please input the first letter of someday:
F↙
friday
程序运行结果示例2:
please input the first letter of someday:
h↙
data error
第一个字母的输入提示信息:“please input the first letter of someday:\n”
第二个字母的输入提示信息:“please input second letter:\n”
用户输入错误提示信息:“data error\n”
输入格式:

" %c" (注意:%c前面有一个空格)

输出格式:

星期一:"monday\n"
星期二:"tuesday\n"
星期三:"wednesday\n"
星期四:"thursday\n"
星期五:"friday\n"
星期六:"saturday\n"
星期日:"sunday\n"
#include 
#include 
#define MAX 7
#define DAY 10

char week[MAX][DAY]={"monday","tuesday","wednesday","thursday","friday","saturday","sunday"};

int main(){
    int i,j,n=0;
    char letter,letter2;
    printf("please input the first letter of someday:\n");
    scanf(" %c",&letter);
    if(letter<='Z'&&letter>='A')
        letter=letter-'A'+'a';
    for(i=0;i<MAX;i++){
        if(letter==week[i][0]){
            n++;
            j=i;
        }
    }
    if(n==1){
        printf("%s\n",week[j]);
        return 0;
    }
    else if(n>1){
        printf("please input second letter:\n");
        scanf(" %c",&letter2);
        for(i=0;i<MAX;i++){
            if(letter==week[i][0]&&letter2==week[i][1]){
                printf("%s\n",week[i]);
                return 0;
            }
        }
    }
    printf("data error\n");
    return 0;
}

你可能感兴趣的:(#,CSP,c语言,编程语言,csp)