标签:
简单的自定义排序
#include<iostream> #include<algorithm> #define maxn 300+5 using namespace std; struct stu { string name; int score; int lev; }; bool cmp(stu x,stu y) { if(x.score==y.score) return x.lev<y.lev; return x.score>y.score; } stu a[maxn],b[maxn]; int main() { cin.sync_with_stdio(false); int n; while(cin>>n) { for(int i=0;i<n;i++) a[i].lev=i,cin>>a[i].name>>a[i].score; for(int i=0;i<n;i++) cin>>b[i].name>>b[i].score; sort(a,a+n,cmp); int flag1=1,flag2=1; for(int i=0;i<n;i++) { if(a[i].score!=b[i].score) flag1=0; if(a[i].name!=b[i].name) flag2=0; } if(!flag1) { cout<<"Error"<<endl; for(int i=0;i<n;i++) cout<<a[i].name<<" "<<a[i].score<<endl; } else if(!flag2) { cout<<"Not Stable"<<endl; for(int i=0;i<n;i++) cout<<a[i].name<<" "<<a[i].score<<endl; } else{cout<<"Right"<<endl;} } return 0; }
标签:
原文地址:http://blog.csdn.net/zafkiel_nightmare/article/details/45273725