- 16分代码
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 100010;
struct user{
string id;
int vir;
int ten;
}sage[MAX], nobleman[MAX], fool[MAX], other[MAX];
int low, high;
bool cmp(user a, user b){
if((a.vir+a.ten) != (b.vir+b.ten)){
return (a.vir+a.ten) > (b.vir+b.ten);
} else if(((a.vir+a.ten) == (b.vir+b.ten)) && (a.vir != b.vir)){
return a.vir > b.vir;
} else {
a.id < b.id;
}
}
int main(int argc, char** argv) {
int n, count=0;
cin >> n >> low >> high;
string id;
int vir, ten;
int i = 0, j = 0, k = 0, m = 0;
while(n--){
cin >> id >> vir >> ten;
if(vir >= high && ten >= high){
sage[i].id = id;
sage[i].vir = vir;
sage[i++].ten = ten;
count++;
} else if(vir >= high && ten < high && ten >=low){
nobleman[j].id = id;
nobleman[j].vir = vir;
nobleman[j++].ten = ten;
count++;
} else if(vir >=low && ten >=low && vir > ten){
fool[k].id = id;
fool[k].vir = vir;
fool[k++].ten = ten;
count++;
} else if(vir >=low && ten >=low && vir <= ten ){
other[m].id = id;
other[m].vir = vir;
other[m++].ten = ten;
count++;
}
}
sort(sage, sage+i, cmp);
sort(nobleman, nobleman+j, cmp);
sort(fool, fool+k, cmp);
sort(other, other+m, cmp);
cout << count << endl;
for(int q = 0; q < i; q++){
cout << sage[q].id << " " << sage[q].vir << " "<< sage[q].ten << endl ;
}
for(int q = 0; q < j; q++){
cout << nobleman[q].id << " " << nobleman[q].vir << " "<< nobleman[q].ten << endl ;
}
for(int q = 0; q < k; q++){
cout << fool[q].id << " " << fool[q].vir << " "<< fool[q].ten << endl ;
}
for(int q = 0; q < m; q++){
cout << other[q].id << " " << other[q].vir << " "<< other[q].ten << endl ;
}
return 0;
}
- 20分代码
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 100010;
struct user{
string id;
int de;
int cai;
int sum;
int flag;
}stu[MAX];
bool cmp(user a, user b){
if(a.flag!=b.flag){
return a.flag < b.flag;
} else if(a.sum != b.sum){
return a.sum > b.sum;
} else if(a.de != b.de){
return a.de > b.de;
} else {
return a.id < b.id;
}
}
int main(){
int n, low, high;
cin >> n >> low >> high;
int m = n;
for(int i = 0; i < n; i++){
cin >> stu[i].id >> stu[i].de >> stu[i].cai;
stu[i].sum = (stu[i].de + stu[i].cai);
if(stu[i].de < low || stu[i].cai < low){
stu[i].flag = 5;
m--;
}
else if(stu[i].de >= high && stu[i].cai >= high){
stu[i].flag = 1;
} else if(stu[i].de >= high && stu[i].cai < high){
stu[i].flag = 2;
} else if(stu[i].de < high && stu[i].cai < high && stu[i].de >= stu[i].cai){
stu[i].flag = 3;
} else {
stu[i].flag = 4;
}
}
sort(stu, stu+n, cmp);
cout << m << endl;
for(int i = 0; i < m; i++){
cout << stu[i].id << " " << stu[i].de << " "<< stu[i].cai << endl ;
}
}