阅读背景:

【结构体】【sort】多重排序

来源:互联网 

Just look at the code,that's OK;

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct student
{
	char name[20];
	int total;
	int chinese;
	int math;
}a[1005];
bool cmp(student x,student y)
{
	if(x.total>y.total)
		return 1;
	else if(x.total==y.total)
	{
		if(x.chinese>y.chinese)
			return 1;
		else if(x.chinese==y.chinese)
		{
			if(x.math>y.math)
				return 1;
		}
	}
	return 0;
}
int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d %d %d",a[i].name,&a[i].total,&a[i].chinese,&a[i].math);
	}
	sort(a,a+n,cmp);
	for(i=0;i<n;i++)
	{
		printf("%s\n",a[i].name);
	}
	return 0;
}#include 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: