排序搞错了,想当然的从后面排到前面,应该是从前面排到后面才是,唉,人老啦 #include <iostream> #include <string> #include <algorithm> using namespace std; struct People { string number; int mark; }; bool cmp(const People &e1,const People &e2) { int i,len=e1.number.length(); if(e1.mark>e2.mark) { return true; } else if(e1.mark<e2.mark) { return false; } else { for(i=2; i<len; i++) { if(e1.number[i]<e2.number[i]) { return true; } else if(e1.number[i]>e2.number[i]) { return false; } } } return false; } People people[1001]; int test[12]; int G,sum,N,M; void Solve() { int i,m,j,t,g; string temp; sum=0; for(i=1; i<=M; i++) { cin>>test[i]; } for(i=0; i<N; i++) { cin>>temp>>m; g=0; for(j=0; j<m; j++) { cin>>t; g+=test[t]; } if(g>=G) { people[sum].number=temp; people[sum].mark=g; sum++; } } sort(people,people+sum,cmp); cout<<sum<<endl; for(i=0; i<sum; i++) { cout<<people[i].number<<" "<<people[i].mark<<endl; } } int main() { // freopen("1236.txt","r",stdin); while(cin>>N && N) { cin>>M>>G; Solve(); } return 0; }