- 谁拿了最多奖学金
- 2016-04-02 11:38:29 @
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
struct STU
{
string name;
int score;
int rating;
char isWorker;
char isWestern;
int pub;
int scholar;
void calcScholar()
{
scholar = (score > 80 and pub > 0? 8000: 0)
+ (score > 85 and rating > 80? 4000: 0)
+ (score > 90? 2000: 0)
+ (score > 85 and isWestern == 'Y'? 1000: 0)
+ (rating > 80 and isWorker == 'Y'? 850: 0);
}
};
bool cmp(STU l, STU r)
{
return (l.scholar = r.scholar? l.name < r.name: l.scholar < r.scholar);
}
istream &operator>>(istream &in, STU &s)
{
in >> s.name >> s.score >> s.rating >> s.isWorker >> s.isWestern >> s.pub;
s.calcScholar();
return in;
}
ostream &operator<<(ostream &out, STU &s)
{
out << s.name << endl << s.scholar;
return out;
}
int main()
{
int size, sum = 0;
cin >> size;
const int SIZE = size;
STU student[SIZE];
for (int i = 0; i < SIZE; i ++)
{
cin >> student[i];
sum += student[i].scholar;
}
sort(student, student + SIZE, cmp);
cout << student[0] << endl << sum << endl;
return 0;
}
1 条评论
-
twd2 LV 9 MOD @ 2016-04-02 17:53:47
bool cmp(STU l, STU r)
{
return (l.scholar = r.scholar? l.name < r.name: l.scholar < r.scholar);
^ ...?
- 1