3 1 000007 James 85 000010 Amy 90 000001 Zoe 60 4 2 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 98 4 3 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 90 0 0
Case 1: 000001 Zoe 60 000007 James 85 000010 Amy 90 Case 2: 000010 Amy 90 000002 James 98 000007 James 85 000001 Zoe 60 Case 3: 000001 Zoe 60 000007 James 85 000002 James 90 000010 Amy 90
这道题我真心想吐槽
哟在三个cmp函数中用三目运算符就一直WA
改成if才AC
无语
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; struct Student { char name[20]; char num[20]; int score; } stu[100005]; bool cmp1(Student x,Student y) { if( strcmp(x.num , y.num) > 0 ) return 0; else return 1; } bool cmp2(Student x,Student y) { if( strcmp(x.name , y.name) > 0 ) return 0; else if(strcmp(x.name , y.name) == 0) { if( strcmp(x.num , y.num) > 0 ) return 0; } return 1; } bool cmp3(Student x,Student y) { if( x.score>y.score ) return 0; else if(x.score==y.score) { if( strcmp(x.num , y.num) > 0 ) return 0; } return 1; } int main() { int n,c,i,cnt = 1; while(cin >> n >> c && n != 0 && c != 0) { for(i = 0; i<n; i++) scanf("%s%s%d",stu[i].num,stu[i].name,&stu[i].score); if(c == 1) sort(stu,stu+n,cmp1); else if(c == 2) sort(stu,stu+n,cmp2); else if (c == 3) sort(stu,stu+n,cmp3); printf("Case %d:\n",cnt++); for(i = 0; i<n; i++) printf("%.6s %s %d\n",stu[i].num,stu[i].name,stu[i].score); } return 0; }