Few weeks ago, a famous software company has upgraded its instant messaging software. A ranking system was released for user groups. Each member of a group has a level placed near his nickname. The level shows the degree of activity of a member in the group.
Each member has a score based his behaviors in the group. The level is determined by this method:
Level | Percentage | The number of members in this level |
---|---|---|
LV1 | / | All members whose score is zero |
LV2 | / | All members who can not reach level 3 or higher but has a positive score |
LV3 | 30% | ⌊(The number of members with a positive score) * 30%⌋ |
LV4 | 20% | ⌊(The number of members with a positive score) * 20%⌋ |
LV5 | 7% | ⌊(The number of members with a positive score) * 7%⌋ |
LV6 | 3% | ⌊(The number of members with a positive score) * 3%⌋ |
- ⌊x⌋ is the maximum integer which is less than or equal to x.
- The member with the higher score will get the higher level. If two members have the same score, the earlier one who joined the group will get the higher level. If there is still a tie, the user with smaller ID will get the higher level.
Please write a program to calculate the level for each member in a group.
Input
There are multiple test cases. The first line of input is an integer T indicating the number of test cases. For each test case:
The first line contains an integer N (1 <= N <= 2000) indicating the number of members in a group.
The next N lines, each line contains three parts (separated by a space):
- The ID of the i-th member Ai (0 <= Ai <= 1000000000). The ID of each member is unique.
- The date of the i-th member joined the group, in the format of YYYY/MM/DD. The date will be in the range of [1900/01/01, 2014/04/06].
- The score Si (0 <= Si <= 9999) of the i-th member.
Output
For each test case, output N lines. Each line contains a string represents the level of the i-th member.
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
struct Node{
int num;
int id;
string year;
int score;
string lv;
}node[2100];
int n;
bool cmp1(Node a,Node b){
if(a.score != b.score) return a.score>b.score;
else if(a.year != b.year) return a.year < b.year;
else if(a.id != b.id) return a.id<b.id;
}
bool cmp2(Node a,Node b){
return a.num < b.num;
}
int main(){
int t;
int i;
int cnt,zero;
int lv1,lv2,lv3,lv4,lv5,lv6;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
cnt = 0;
zero = 0;
for(i = 0;i<n;i++){
node[i].num = i;
cin>>node[i].id>>node[i].year>>node[i].score;
if(node[i].score>0) cnt++;
if(node[i].score==0) zero ++;
}
lv1 = lv2 = lv3 = lv4 = lv5 = lv6 = 0;
lv1 = zero;
lv3 = cnt * 0.3;
lv4 = cnt * 0.2;
lv5 = cnt * 0.07;
lv6 = cnt * 0.03;
lv2 = n - lv1-lv3-lv4-lv5-lv6;
//printf("%d %d %d %d %d %d\n",lv1,lv2,lv3,lv4,lv5,lv6);
sort(node,node+n,cmp1);
for(i = 0;i<n;i++){
if(lv6!=0){
node[i].lv = "LV6";
lv6--;
continue;
}
else if(lv5!=0) {
node[i].lv = "LV5";
lv5 --;
continue;
}
else if(lv4!=0){
node[i].lv = "LV4";
lv4--;
continue;
}
else if(lv3 !=0) {
node[i].lv = "LV3";
lv3--;
continue;
}
else if(lv2!=0){
node[i].lv = "LV2";
lv2--;
continue;
}
else if(lv1!=0){
node[i].lv = "LV1";
lv1--;
continue;
}
}
sort(node,node+n,cmp2);
for(i = 0;i<n;i++) cout<<node[i].lv<<endl;
}
return 0;
}
//先求出各种等级的人数,然后通过两次排序,即可求得答案。