//成绩排行
//输入
//CS00000001 4 110
//CS00000002 4 120
//CS00000003 5 150
//输出
//CS00000003 5 150
//CS00000001 4 110
//CS00000002 4 120
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
const int N=100;
struct student{
char bianhao[N];
int number;
int score;
}st[N];
bool comp1( student a, student b)
{
if(a.number>b.number)
return true;
else
if(a.number==b.number)
{
if(a.score<b.score)
return true;
else
return false;
}
else return false;
}
int main()
{
FILE *fp;
char str[N];
int i=0,j=0,count=0;
if((fp=fopen("123.txt","r"))==NULL)
printf("file cannot open \n");
else
printf("file opened for writing \n");
while (!feof(fp))
{
fscanf(fp,"%s %d %d",st[i].bianhao,&st[i].number,&st[i].score);
i++;
}
i=i-1;
sort(st,st+i,comp1);
for(int j=0;j<i;j++){
cout<<st[j].bianhao<<" ";
cout<<st[j].number<<" ";
cout<<st[j].score<<" "<<endl;
}
if(fclose(fp)!=0)
printf("file cannot be closed \n");
else
{
printf("file is now closed \n");
}
system("pause");
return 0;
}