zoj 3770 Ranking System

zoj 3770 Ranking System,第1张

zoj 3770 Ranking System
#include <iostream>#include <map>#include <stdio.h>#include <algorithm>using namespace std;const int MAX_N = 2000 + 100;int n, T, cnt;struct Rank{    int ymd;    int score;    int id;    string lv;};int y, m, d, id, score;Rank r[MAX_N];int a[MAX_N];int cmp(int m, int n){    if(r[m].score != r[n].score)        return r[m].score > r[n].score;    else if(r[m].score == r[n].score)    {        if(r[m].ymd != r[n].ymd) return r[m].ymd < r[n].ymd;        else if(r[m].ymd == r[n].ymd) return r[m].id < r[n].id;    }}int lv[6];int main(){    scanf("%d", &T);    while(T--)    {        scanf("%d", &n);        int cnt = 0;        for(int i = 0; i < n; i++)        { scanf("%d %d/%d/%d %d", &r[i].id, &y, &m, &d, &r[i].score); r[i].ymd = y * 10000 + m * 100 + d; a[i] = i; if(r[i].score != 0)     cnt++;        }        sort(a, a + n, cmp);        lv[6] = (int)(cnt * 0.03);        lv[5] = (int)(cnt * 0.07);        lv[4] = (int)(cnt * 0.2);        lv[3] = (int)(cnt * 0.3);        lv[2] = cnt - lv[6] - lv[5] - lv[4] - lv[3];        lv[1] = n - cnt;        for(int i = 0; i < n; i++)        { if(lv[6] != 0) {     r[a[i]].lv = "LV6";     lv[6]--; } else if(lv[5] != 0) {     r[a[i]].lv = "LV5";     lv[5]--; } else if(lv[4] != 0) {     r[a[i]].lv = "LV4";     lv[4]--; } else if(lv[3] != 0) {     r[a[i]].lv = "LV3";     lv[3]--; } else if(lv[2] != 0) {     r[a[i]].lv = "LV2";     lv[2]--; } else     r[a[i]].lv = "LV1";        }        for(int i = 0; i < n; i++) cout << r[i].lv << endl;    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4878923.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-11
下一篇 2022-11-11

发表评论

登录后才能评论

评论列表(0条)

保存