#include <cstdio> #include <iostream> #include <cstring> #include <cstdlib> using namespace std; #ifdef ONLINE_JUDGE #define FINPUT(file) 0 #define FOUTPUT(file) 0 #else #define FINPUT(file) freopen(file,"r",stdin) #define FOUTPUT(file) freopen(file,"w",stdout) #endif struct Acm{ char name[110]; int score; int punish; }; int comp(const void *b,const void *a) { if(((Acm*)a)->score !=((Acm*)b)->score) return ((Acm*)a)->score - ((Acm*)b)->score; else if(((Acm*)a)->punish !=((Acm*)b)->punish) return ((Acm*)b)->punish - ((Acm*)a)->punish; else if (strcmp(((Acm*)a)->name, ((Acm*)b)->name)!=0) { return strcmp(((Acm*)b)->name, ((Acm*)a)->name); } } int main() { FINPUT("in.txt"); FOUTPUT("out.txt"); int n; while(cin>>n && n>=1 && n<=100) { Acm *a = new Acm[n]; for(int i=0;i<n;i++) { cin>>a[i].name>>a[i].score>>a[i].punish; } qsort(a,n,sizeof(Acm),comp); for(int i=0;i<n;i++) { cout<<a[i].name<<endl; } delete [] a; } return 0; }
原文地址:http://blog.csdn.net/daringpig/article/details/25716835