【来源】
【分析】
先排序,再按照等级人数限制进行划分即可。
【源码】
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
struct User{
int id;
string joindate;
int score;
int level;
int index;
User(){
level = 0;
}
};
bool compare(User u1, User u2)
{
if (u1.score != u2.score){
return u1.score > u2.score;
}
else{
if (u1.joindate != u2.joindate){
return u1.joindate < u2.joindate;
}
else{
return u1.id < u2.id;
}
}
}
bool compare_back(User u1, User u2)
{
return u1.index < u2.index;
}
int main()
{
int T;
cin >> T;
while (T--){
int n;
cin >> n;
vector<User> users;
int posusers = 0;;
for(int i = 0; i < n; ++i){
User user;
cin >> user.id >> user.joindate >> user.score;
user.index = i;
if (user.score == 0){
user.level = 1;
}
else{
++posusers;
}
users.push_back(user);
}
sort(users.begin(), users.end(), compare);
int level1 = n - posusers;
int level6 = floor(0.03*posusers);
int level5 = floor(0.07*posusers);
int level4 = floor(0.20*posusers);
int level3 = floor(0.30*posusers);
int level2 = n - level1 - level3 - level4
- level5 - level6;
int count = 0;
for (int i = 0; i < level6; ++i){
users[count].level = 6;
++count;
}
for (int i = 0; i < level5; ++i){
users[count].level = 5;
++count;
}
for (int i = 0; i < level4; ++i){
users[count].level = 4;
++count;
}
for (int i = 0; i < level3; ++i){
users[count].level = 3;
++count;
}
for (int i = 0; i < level2; ++i){
users[count].level = 2;
++count;
}
sort(users.begin(), users.end(), compare_back);
for (int i = 0; i < n; ++i){
cout << "LV" << users[i].level << endl;
}
}
return 0;
}
【点评】
常规的模拟题。