Created
December 12, 2014 15:50
-
-
Save 92thunder/b3377497417fd06e4356 to your computer and use it in GitHub Desktop.
12/12講座問題2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <algorithm> | |
using namespace std; | |
class Student { | |
public: | |
char name; | |
int math, eng; | |
bool operator < (const Student &s ) const { | |
if(math == s.math) | |
return eng > s.eng; | |
return math > s.math; | |
} | |
}; | |
int main() { | |
Student stu[5]; | |
stu[0].name = 'a'; stu[0].math = 2; stu[0].eng = 8; | |
stu[1].name = 'b'; stu[1].math = 9; stu[1].eng = 3; | |
stu[2].name = 'c'; stu[2].math = 8; stu[2].eng = 3; | |
stu[3].name = 'd'; stu[3].math = 2; stu[3].eng = 2; | |
stu[4].name = 'e'; stu[4].math = 5; stu[4].eng = 3; | |
sort( stu, stu + 5); | |
for(int i=0; i<5; i++) { | |
printf("%c %d %d\n", stu[i].name, stu[i].math, stu[i].eng); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment