考试排名(xdoj243 )

试题名称 考试排名

时间限制: 1 秒

内存限制: 256KB

问题描述

某考试有5道题和1道附加题,每题最高得分20分,总分计算为所有题目分数之和。给出一组考生的数据,对其按照总分从高到低进行排名,总分相同时按附加题得分高者优先。

输入说明

第一行为一个整数N,表示考生个数(N小于100),后面N行为考生数据,每行包含考生姓名(长度不超过20个字符)以及6个以空格分隔的整数,分别表示第一题到第五题以及附加题的得分(最后一项)。

输出说明

输出排序结果,每行为一个考生的姓名、总分、附加题得分,以空格分开。

输入样例


Jony 18 20 20 20 20 20 
Kavin 20 20 20 20 20 18 
Kaku 15 15 15 15 15 15

输出样例

Jony 118 20 
Kavin 118 18 
Kaku 90 15

直接甩代码了

#include <stdio.h>

struct Student {
	char name[20];//保存名字
	int score[5];//5道题成绩
	int  end;//附加题成绩
	int sum;//总分成绩
};
int main() {
	void input(struct Student stu[], int n);
	struct Student sort(struct Student stu[], int n);
	void print(struct Student stu[], int n);
	struct Student stu[100], *p = stu;
	int n;
	scanf("%d", &n);
	input(p, n);
	sort(p, n);
	print(p, n);
	return 0;
}

void input(struct Student stu[], int n) {
	for (int i = 0; i < n; i++) {
		scanf("%s %d %d %d %d %d %d", stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2], &stu[i].score[3],
		      &stu[i].score[4], &stu[i].end);
		stu[i].sum = (stu[i].score[0] + stu[i].score[1] + stu[i].score[2] + stu[i].score[3] + stu[i].score[4] + stu[i].end);
	}
}

struct Student sort(struct Student stu[], int n) {
	struct Student temp;
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - i - 1; j++) {
			if (stu[j].sum < stu[j + 1].sum) {
				temp = stu[j];
				stu[j] = stu[j + 1];
				stu[j + 1] = temp;
			} else if (stu[j].sum == stu[j + 1].sum) {
				if (stu[j].end < stu[j + 1].end) {
					temp = stu[j];
					stu[j] = stu[j + 1];
					stu[j + 1] = temp;
				}
			}
		}
	}
}

void print(struct Student stu[], int n) {
	for (int i = 0; i < n; i++) {
		printf("%s %d %d\n", stu[i].name, stu[i].sum, stu[i].end);
	}
}

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值