哈尔滨工业大学-程序设计基础(C语言)-第12周编程题在线测试

10 篇文章 0 订阅

1. 计算时间差V2.0(4分)

题目内容:

用结构体定义时钟类型,编程从键盘任意输入两个时间(例如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 <stdio.h>
#include <math.h>
#include <string.h>

typedef struct clock

{

    int hour;

    int minute;

    int second;

} CLOCK;

CLOCK CalculateTime(CLOCK t1, CLOCK t2);

int main()
{  
	CLOCK t1, t2, t3;
    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);
	t3 = CalculateTime(t1, t2);
	printf("%dhour,%dminute\n", t3.hour, t3.minute);
}

CLOCK CalculateTime(CLOCK t1, CLOCK t2)
{
	CLOCK t3;
	
	if (t1.hour >= t2.hour)
	{
		if(t1.minute >= t2.minute){
			t3.hour = t1.hour - t2.hour; 
			t3.minute = t1.minute - t2.minute;
		}else{
			t1.hour -= 1;
			t3.hour = t1.hour - t2.hour;
			t3.minute = t1.minute + 60 - t2.minute;
		}
	}else{
		if(t2.minute >= t1.minute){
			t3.hour = t2.hour - t1.hour; 
			t3.minute = t2.minute - t1.minute;
		}else{
			t2.hour -= 1;
			t3.hour = t2.hour - t1.hour;
			t3.minute = t2.minute + 60 - t1.minute;
		}
	}
	
	
	return t3;
}

2. 奖学金发放(4分)

题目内容:

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

  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"
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);

main ()
{
	int n, m;
	printf("Input n:");  // 学生人数
	scanf("%d", &n);
	
	WIN s[n];
	for(int i=0; i<n; i++){
		//TODO
		printf("Input name:");  // 姓名
		scanf("%s", &s[i].name);
		
		printf("Input final score:");  // 期末平均成绩
		scanf("%d", &s[i].finalScore);
		
		printf("Input class score:");  // 班级评议成绩
		scanf("%d", &s[i].classScore);
		
		printf("Class cadre or not?(Y/N):");  // 是否学生干部
		scanf(" %c", &s[i].work);
		
		printf("Students from the West or not?(Y/N):");  // 是否西部学生
		scanf(" %c", &s[i].west);
		
		printf("Input the number of published papers:");  // 论文数
		scanf("%d", &s[i].paper);
		
		Addup(s, i);
	}
	
	m = FindMax(s, n);  // 返回奖学金最高的学生的下标
	printf("%s get the highest scholarship %d\n", s[m].name, s[m].scholarship);  // 输出获得奖学金总数最高的学生
	
}

void Addup(WIN stu[], int n)
{
	int score = 0;
	if(stu[n].finalScore > 80 && stu[n].paper >=1){
		score += 8000;
	}
	if(stu[n].finalScore >85 && stu[n].classScore > 80){
		score += 4000;
	}
	if(stu[n].finalScore> 90){
		score += 2000;
	}
	if(stu[n].finalScore> 85 && (stu[n].west == 'Y' || stu[n].west == 'y')){
		score += 1000;
	}
	if(stu[n].classScore > 80 && (stu[n].work == 'Y' || stu[n].work == 'y')){
		score += 850;
	}
	
	stu[n].scholarship = score;
	printf("name:%s,scholarship:%d\n", stu[n].name, stu[n].scholarship);
}

int FindMax(WIN student[], int n)
{
	int j=0, max=0;
	for(int i=0;i<=n;i++){
		if(student[i].scholarship > max){
			max = student[i].scholarship;
			j = i;
		}
	}
	
	return j;
}

3. 评选最牛群主v1.0(4分)

题目内容:

现在要评选最牛群主,已知有3名最牛群主的候选人(分别是tom,jack和rose),有不超过1000人参与投票,最后要通过投票评选出一名最牛群主,从键盘输入每位参与投票的人的投票结果,即其投票的候选人的名字,请你编程统计并输出每位候选人的得票数,以及得票数最多的候选人的名字。候选人的名字中间不允许出现空格,并且必须小写。若候选人名字输入错误,则按废票处理。

程序运行结果示例1:

Input the number of electorates:8↙

Input vote 1:tom↙

Input vote 2:jack↙

Input vote 3:rose↙

Input vote 4:tom↙

Input vote 5:rose↙

Input vote 6:rose↙

Input vote 7:jack↙

Input vote 8:rose↙

Election results:

tom:2

jack:2

rose:4

rose wins

程序运行结果示例2:

Input the number of electorates:5↙

Input vote 1:tom↙

Input vote 2:mary↙

Input vote 3:rose↙

Input vote 4:jack↙

Input vote 5:tom↙

Election results:

tom:2

jack:1

rose:1

tom wins

提示输入候选人数量:“Input the number of electorates:”

提示输入候选人: “Input vote %d:”

输入格式:

输入候选人数量:"%d"

输入候选人姓名:"%s"   

输出格式:

输出候选人得票数:"%s:%d\n"     

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

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

main ()
{	
	int n;
	char name[][5] = {"tom","jack","rose"};
	int num[3] = {0, 0, 0};
	char vote_name[5];
	
	printf("Input the number of electorates:");
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		printf("Input vote %d:", i);
		scanf("%s", vote_name);
		
		for(int j=0; j<3; j++){
			if(strcmp(vote_name, name[j]) == 0)
			{
				num[j]++;
			}
		}
		
	
	}
	
	printf("Election results:\n");
	
	for(int i=0; i<3; i++){
		printf("%s:%d\n", name[i], num[i]);
	}
	
	int max = num[0];
	int m = 0;
	for(int i=1; i<3; i++){
		if(max < num[i]){
			max = num[i];
			m = i;
		}	
	}
	
	printf("%s wins\n", name[m]);
		
	
}

4. 星期判断(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 <stdio.h>

int main(){
    char first,second;
    printf("please input the first letter of someday:\n");
    scanf(" %c",&first);
    if (first=='M' || first=='m') {
        printf("monday\n");
        return 0;
    }
    if (first=='W' || first=='w') {
        printf("wednesday\n");
        return 0;
    }
    if (first=='F' || first=='f') {
        printf("friday\n");
        return 0;
    }
    if (first=='T' || first=='S' || first=='t' || first=='s') {
        printf("please input second letter:\n");
        scanf(" %c",&second);
    }else{
        printf("data error\n");
        return 0;
    }
    if ((first=='T' || first=='t') && second=='u') {
        printf("tuesday\n");
        return 0;
    }
    if ((first=='T' || first=='t') && second=='h') {
        printf("thursday\n");
        return 0;
    }
    if ((first=='S' || first=='s') && second=='a') {
        printf("saturday\n");
        return 0;
    }
    if ((first=='S' || first=='s') && second=='u') {
        printf("sunday\n");
        return 0;
    }
    if (second!='u' || second!= 'h' || second!='a' || second!='u') {
        printf("data error\n");
    }
    return 0;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
谁拿了最多奖学金 • 某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,获取的条件各自不同: • 1) 院士奖学金,每人8000元,期末平均成绩高于80分( >80),并且在本学期内发表1篇或1篇以上论文的学生均可获得; • 2) 五四奖学金,每人4000元,期末平均成绩高于85分( >85),并且班级评议成绩高于80分(>80)的学生均可获得; • 3) 成绩优秀奖,每人2000元,期末平均成绩高于90分( >90)的学生均可获得; 4) 西部奖学金,每人1000元,期末平均成绩高于85分( >85)的西部省份学生均可获得;5) 班级贡献奖,每人850元,班级评议成绩高于80分(>80)的学生干部均可获得; • 只要符合条件就可以得奖,每项奖学金的获奖人数没有限制,每名学生也可以同时获得多项奖学金。 • 例如姚林的期末平均成绩是87分,班级评议成绩82分,同时他还是一位学生干部,那么他可以同时获得五四奖学金 和班级贡献奖,奖金总数是4850元。现在给出若干学生的相关数据,请计算哪些同学获得的奖金总数最高(假设总 有同学能满足获得奖学金的条件)。 Input 输入的第一行是一个整数N(1 <= N <= 100),表示学生的总数。 • 接下来的N行每行是一位学生的数据,从左向右依次是姓名,期末平均成绩,班级评议成绩,是否是学生干部,是 否是西部省份学生,以及发表的论文数。姓名是由大小写 英文字母组成的长度不超过20的字符串(不含空格);期末平均成绩和班级评议成绩都是0到100之间的整数(包括0和100);是否是学生干部和是否是西部省份学生分别用一个字符表示,Y表示是,N表示不是;发表的论文数是0 到10的整数(包括0和10)。每两个相邻数据项之间用一个空格分隔。 Output 输出包括三行,第一行是获得最多奖金的学生的姓名,第二行是这名学生获得的奖金总数。如果有两位或两位以上 的学生获得的奖金最多,输出他们之中在输入文件中出现 最早的学生的姓名。第三行是这N个学生获得的奖学金的总数。 • • Sample Input Sample Output 4 YaoLin 87 82 Y N 0 ChenRuiyi ChenRuiyi 88 78 N Y 1 9000 LiXin 92 88 N N 0 28700 ZhangQin 83 87 Y N 1
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值