#include "stdafx.h"
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
struct student
{
char name[100];
int age;
int grade;
};
//插入法排序
void qSort(student stu[],int n)
{
student temp;
int j;
for(int i=1;i<n;i++)
{
temp=stu[i];
for( j=i-1;j>=0&&temp.grade<stu[j].grade;j--)
stu[j+1]=stu[j];
j++;
stu[j]=temp;
while(j>=1&&stu[j].grade==stu[j-1].grade&&strcmp(stu[j].name,stu[j-1].name)<0)
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
j--;
}
while(stu[j].grade==stu[j-1].grade&&strcmp(stu[j].name,stu[j-1].name)==0&&stu[j].age<stu[j-1].age)
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
j--;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
student students[1000];
int n;
while(cin>>n&&n!=EOF)
{
for(int i=0;i<n;i++)
{
cin>>students[i].name>>students[i].age>>students[i].grade;
}
qSort(students,n);
for(int i=0;i<n;i++)
{
cout<<students[i].name<<" "<<students[i].age<<" "<<students[i].grade<<endl;
}
}
return 0;
}
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
struct student
{
char name[100];
int age;
int grade;
};
//插入法排序
void qSort(student stu[],int n)
{
student temp;
int j;
for(int i=1;i<n;i++)
{
temp=stu[i];
for( j=i-1;j>=0&&temp.grade<stu[j].grade;j--)
stu[j+1]=stu[j];
j++;
stu[j]=temp;
while(j>=1&&stu[j].grade==stu[j-1].grade&&strcmp(stu[j].name,stu[j-1].name)<0)
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
j--;
}
while(stu[j].grade==stu[j-1].grade&&strcmp(stu[j].name,stu[j-1].name)==0&&stu[j].age<stu[j-1].age)
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
j--;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
student students[1000];
int n;
while(cin>>n&&n!=EOF)
{
for(int i=0;i<n;i++)
{
cin>>students[i].name>>students[i].age>>students[i].grade;
}
qSort(students,n);
for(int i=0;i<n;i++)
{
cout<<students[i].name<<" "<<students[i].age<<" "<<students[i].grade<<endl;
}
}
return 0;
}