一道题带来的激动

就在刚刚,我终于解决了一道困惑我许久的问题,并从中学到了很多新东西,答案正确的那一瞬间真的太激动了,先看题目(我还是个菜鸟,不要嘲讽我题目简单呜呜)

输入n个学生数据记录(姓名、学号,5门课成绩)算出总分并且进行排序,按总分最后从高到低输出这些数据。

输入

第一行输入学生的个数N接下来的N行输入学生的姓名,学号,5门科的成绩。

输出

一共输出N行,每行输出学生的姓名,学号,及总分(格式:total=?),每个数据相隔一个空格

输入样例 1 

3
A 200701 98 125 100 96 85
B 200702 100 100 100 100 120
C 200703 130 80 70 50 50

输出样例 1

B 200702 total=520
A 200701 total=504
C 200703 total=380
#include<stdio.h>
#include<ctype.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>

//
//输入n个学生数据记录(姓名、学号,5门课成绩)算出总分并且进行排序,按总分最后从高到低输出这些数据。
//
//
//输入
//第一行输入学生的个数N接下来的N行输入学生的姓名,学号,5门科的成绩。
//
//
//输出
//一共输出N行,每行输出学生的姓名,学号,及总分(格式:total=?),每个数据相隔一个空格
//
//
//输入样例 1 
//
//3
//A 200701 98 125 100 96 85
//B 200702 100 100 100 100 120
//C 200703 130 80 70 50 50
//输出样例 1
//
//B 200702 total=520
//A 200701 total=504
//C 200703 total=380
//


int main()
{
	int i,j,x;
   struct Student{
   	char name[100];
   	int degree;
   	int score[5];
   	int sum;
   };
      int n;
      scanf("%d",&n);
      struct Student student[n];
      for(i=0;i<n;i++)
      {
      	student[i].sum=0;
	  }

	for(i=0;i<n;i++)
	{
		
		scanf("%s",&student[i].name);
		scanf("%d",&student[i].degree);
		for(x=0;x<5;x++)
		{
			scanf("%d",&student[i].score[x]);
			student[i].sum+=student[i].score[x];
		}
	}
	//把sum按从高到低排序
	
	 for(i=0;i<n-1;i++) 
	{
	for(j=0;j<n-i-1;j++)
	{
			if(student[j+1].sum>student[j].sum)
			{
			struct Student m;
			m=student[j+1];
			student[j+1]=student[j];
			student[j]=m;
			}
	}
	}

		for(i=0;i<n;i++){
	printf("%s %d total=%d\n",student[i].name,student[i].degree,student[i].sum);
    }
	return 0;
 } 


为了这道题目学会了结构体,冒泡排序等知识,真的让我收获很多,浅浅记录一下

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值