Skip to content

Instantly share code, notes, and snippets.

@92thunder
Created December 12, 2014 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 92thunder/b3377497417fd06e4356 to your computer and use it in GitHub Desktop.
Save 92thunder/b3377497417fd06e4356 to your computer and use it in GitHub Desktop.
12/12講座問題2
#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