5-37 模拟EXCEL排序 (25分)

5-37 模拟EXCEL排序 (25分)_第1张图片

#include "iostream"
#include "string.h"
#include "cstring"
#include "algorithm"
#include "vector"
using  namespace std;
#define Max 100005
struct Stu
{
  char name[10];	
  char Xuehao[10];
  int score;
};

Stu T[Max];
 
bool C_1(Stu A,Stu B)
{
	return strcmp(A.Xuehao,B.Xuehao)<0;
}
bool C_2(Stu A,Stu B)
{   
	if(strcmp(A.name,B.name)!=0)
	return strcmp(A.name,B.name)<0;
	else
	return strcmp(A.Xuehao,B.Xuehao)<0;
}
bool C_3(Stu A,Stu B)
{
    if(A.score!=B.score)
	return A.score<B.score;
	else
	return strcmp(A.Xuehao,B.Xuehao)<0;
}
 
 
 
int main()
{     
     
   //	freopen("1.txt","r",stdin);
 
    int i,m,n;
	scanf("%d%d",&m,&n); //m是条数 n是排序的标准
     
	for(i=0;i<m;i++)
	{
     scanf("%s%s%d",T[i].Xuehao,T[i].name,&T[i].score);
	}

    if(n==1)
    sort(T+0,T+m,C_1);
    if(n==2)
    sort(T+0,T+m,C_2);
    if(n==3)
    sort(T+0,T+m,C_3);

    for(i=0;i<m;i++)
	 printf("%.6s %s %d\n",T[i].Xuehao,T[i].name,T[i].score);
 
	 
	return 0;
}


你可能感兴趣的:(5-37 模拟EXCEL排序 (25分))