PAT 1028 List Sorting (25)

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;


struct Student
{
	char stu_id[15];
	char strName[15];
	int score;
};

Student arrStu[100000+5];

int C;

bool greaterMark(const Student &stu1, const Student &stu2)
{
	if(C == 1)
	{
		return strcmp(stu1.stu_id,stu2.stu_id)<0;
	}
	else if(C == 2)
	{
		if(strcmp(stu1.strName,stu2.strName) != 0)
			return strcmp(stu1.strName,stu2.strName) < 0;
		else
			return strcmp(stu1.stu_id,stu2.stu_id) < 0;
	}
	else if(C == 3)
	{
		if(stu1.score != stu2.score)
			return stu1.score < stu2.score;
		else 
			return strcmp(stu1.stu_id,stu2.stu_id) < 0;
	}
}

void optput(int N)
{
	for(int i=0; i<N; i++)
		cout<<arrStu[i].stu_id<<" "<<arrStu[i].strName<<" "<<arrStu[i].score<<endl;
}

int main()
{	
	int N;
	scanf("%d %d",&N,&C);
	Student stu;
	for(int i=0; i<N; i++)
	{
		scanf("%s",arrStu[i].stu_id);
		scanf("%s",arrStu[i].strName);		
		scanf("%d",&arrStu[i].score);
	}
	sort(arrStu,arrStu + N, greaterMark);
	optput(N);
	return 0;
}

  

posted @ 2012-12-11 18:22  Frank@609  Views(327)  Comments(0Edit  收藏  举报