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

zoj 2953 Golf Rank

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

zoj 2953 Golf Rank

#include <stdio.h>#include <iostream>#include <string.h>#include <math.h>#include <map>#include <string>#include <algorithm>using namespace std;map <string,int> mp;string name;string hash[1000];int sc[1000],num[1000],pal[1000],r[1000],mc[1000];bool cmp(int x,int y){    if (sc[x]!=sc[y]) return sc[x]<sc[y];    double num1,num2;    num1=(double)sc[x]/(double)num[x];    num2=(double)sc[y]/(double)num[y];    if (fabs(num1-num2)>1e-8)        return num1<num2;    return hash[x]<hash[y];}int main(){    int t;    scanf("%d",&t);    for (int ii=1;ii<=t;ii++)    {        memset(sc,0,sizeof(sc));        memset(num,0,sizeof(num));        mp.clear();        int h;        scanf("%d",&h);        for (int i=0;i<h;i++) scanf("%d",&pal[i]);        printf("Tournament %dn",ii);        int id=0;        while (cin >> name&&name!="EndOfTournament")        { if (name=="ShowRank") {     puts("Place  Name        Score  Holes");     for (int i=0;i<id;i++)         r[i]=i;     sort(r,r+id,cmp);     for (int j=0;j<id;j++)     {         int now=0;         if (j!=0&&sc[r[j]]==sc[r[j-1]])  mc[r[j]]=mc[r[j-1]];         else mc[r[j]]=j+1;         printf("%5d  %s",mc[r[j]],hash[r[j]].c_str());         int delta=12-hash[r[j]].size();         for (int k=0;k<delta;k++)  printf(" ");         if (sc[r[j]]<=0)  printf("%5d  ",sc[r[j]]);         else         {  int cntt=0;  int num=sc[r[j]];  while (num!=0)  {      cntt++;      num/=10;  }  for (int k=0;k<5-cntt-1;k++)      printf(" ");  printf("+%d  ",sc[r[j]]);         }         if (num[r[j]]==h)  printf("%5cn",'F');         else  printf("%5dn",num[r[j]]);     }     printf("n");     continue; } int temp; scanf("%d",&temp); if (mp.find(name)==mp.end()) {     mp.insert(pair<string,int>(name,id));     hash[id]=name;     num[id]=0;     sc[id]+=temp-pal[num[id]];     num[id]++;     id++; } else {     int now=mp[name];     sc[now]+=temp-pal[num[now]];     num[now]++; }        }    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372183.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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