栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2513 Final Ranklist

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2513 Final Ranklist

#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<stdio.h>using namespace std;struct Team {    int  cnt;    string name;    string st[12];};char buf[200];int tn, pn;int pro[12];int idx[3008];Team trp[3008];int cmp(int a, int b){    if(trp[a].cnt != trp[b].cnt) return -trp[a].cnt + trp[b].cnt;    return strcmp(trp[a].st[pn].c_str(),trp[b].st[pn].c_str());}struct lessThan {    bool operator()(const int &a, const int&b)const{        int v = cmp(a,b);        if(v == 0 ){ return strcmp(trp[a].name.c_str(), trp[b].name.c_str()) < 0;        }        return v < 0;    }};void fun(){    int i, r = 1, j;    for(i=0; i<tn; i++){        if(i && cmp(idx[i], idx[i-1])!=0){ r++;        }        pro[trp[idx[i]].cnt] ++;        printf("%d %s %d", r, trp[idx[i]].name.c_str(), trp[idx[i]].cnt);        for(j=0; j<=pn; j++){ printf(" %s", trp[idx[i]].st[j].c_str());        }        printf("n");    }    printf("Total Teams: %d", tn);    for(i=pn; i>0; i--){        if(pro[i]==0) continue;        printf("; Solved %d: %d", i, pro[i]);    }    printf(".n");}int proInfo(char *s){    scanf("%s ", s);    int t = strlen(s);    if (t < 8)        return -1;    s += t;    *s ++ = ' ';    scanf("%s ", s);    return 1;}int readIn(){    int sec;     if(scanf("%d%d ",&sec,&pn)<0)        return 0;    memset(pro, 0, sizeof(pro));    int i,n,r,p;    tn = 0;    while(sec--){        scanf("%d ", &n);        for(i=0; i<n; i++){ idx[tn+i] = tn + i; scanf("%d%s%d ", &r, buf,&trp[tn+i].cnt); trp[tn+i].name = buf; for(p=0; p<pn; p++){     r = proInfo(buf);     trp[tn+i].st[p] = buf; } scanf("%s ", buf); trp[tn+i].st[pn] = buf;        }        tn += n;    }    sort(idx, idx+tn, lessThan());    return 1;}int main(){    bool f = true;    while(readIn() > 0){        if(!f) printf("n");        fun();        f = false;    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/378616.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号