Few weeks ago, a famous software company had upgraded its instant messaging software. A ranking system is released for user groups. Each member of a group had a level placed near his nickname. The level shows the degree of activity of a member in the group.
Each member have a score based his behaviors in the group. The level was determined by this method:
level |
Percentage |
The number of members in This level |
LV1 |
/ |
All members whose score is zero |
LV2 |
/ |
all, who can, reach level 3 or higher but have 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 would get the higher level. If the members of the same score, the earlier one who joined the group would get the higher level. If There is still a tie, the user with smaller ID would get the higher level.
Please write a program to calculate the level for each member in a group.
Input
There is multiple test cases. The first line of input was an integer indicating the number of T test cases. For each test case:
The first line contains an integer N (1 <= <=) indicating the number of members in N 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 the YYYY/MM/DD. The date'll is 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.
Sample Input
15123456 2011/03/11 308123457 2011/03/12 308333333 2012/03/18 4555555 2014/02/11 0278999 2011/03/18 308
Sample Output
Lv3lv2lv2lv1lv2
I didn't do it at the start of the game because it looked complicated, and there was a form.
Later found quite simple, hey, then go to a, but unexpectedly a small problem card i n long, and is because the decimal point is written ', ' cause has been WA, drunk, or not careful ah.
The general meaning of the topic is:
You are ordered by rank:
First, according to the score to row, if the score is the same according to the time to row, then followed by the ID to row;
Then ask you to output how much each person's LV is.
Then it is equivalent to a three-level sort of variable. After all, there are only 6 levels, so it's good to figure out the number of people at each level and sort it out in turn.
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm>using namespace Std;struct Node{int x;//saved the ordinal; int id;int yy,mm,dd;int s;} A[2005];bool CMP (node A,node b) {if (A.S!=B.S) return a.s>b.s;if (A.S==B.S) {if (a.yy==b.yy && a.mm==b.mm) Return A.dd<b.dd;if (a.yy==b.yy) return A.mm<b.mm;return a.yy<b.yy;} return a.id<b.id;} int main () {int t,n,sum,k,i,j;int f[2005];scanf ("%d", &t), while (t--) {memset (a,0,sizeof (a)); memset (F,0,sizeof (f)); scanf ("%d", &n), Sum=0;for (i=1;i<=n;i++) {scanf ("%d%d/%d/%d%d", &a[i].id,&a[i ].YY,&A[I].MM,&A[I].DD,&A[I].S); A[i].x=i;//sum is the number of people with records greater than 0; if (a[i].s>0) sum++;} int D6,d5,d4,d3;sort (A+1,A+1+N,CMP);d 6=sum*0.03; d5=sum*0.07; d4=sum*0.2; D3=sum*0.3;for (i=1;i<=n;i++) {if (!A[I].S) f[a[i].x]=1; else if (d6) {f[a[i].x]=6; d6--; }else if (D5) {f[a[i].x]=5; d5--; }else if (D4) {f[a[i].x]=4; d4--; }else if (D3) {f[a[i].x]=3; d3--; }else {f[a[i].x]=2; }}for (i=1;i<=n;i++) {printf ("lv%d\n", F[i]);}}}
Also, under my verification, it is possible to save that ID with a string type,
and write a.id<b.id; directly at the time of comparison. Can also come to judge;
ZOJ-3770 (Ranking System)