UVA10194 - Football (aka Soccer)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1135

好繁琐的一道模拟题 细节很重要 编译错误一次  把字符串结尾写错WA一次 多了getchar()WA一次 多了以空格PE一次 最后AC...3个多小时

用了一下map map还是很方便的

View Code
  1 #include <iostream>
  2 #include<map>
  3 #include<stdio.h>
  4 #include<string>
  5 #include<string.h>
  6 #include<stdlib.h>
  7 using namespace std;
  8 typedef struct node
  9 {
 10     int a,b,c,d,e,f,g,h,i;
 11     char j[31];
 12     node()
 13     {
 14         a = 0;
 15         b = 0;
 16         c = 0;
 17         d = 0;
 18         e = 0;
 19         f = 0;
 20         g = 0;
 21         h = 0;
 22         i = 0;
 23     }
 24 }st;
 25 map <string, int> ff;
 26 int cmp(const void *x,const void *y)
 27 {
 28     if(((st *)x)->b!=((st *)y)->b)
 29     return ((st *)y)->b-((st *)x)->b;
 30     else
 31     if(((st *)x)->d!=((st *)y)->d)
 32     return (((st *)y)->d-((st *)x)->d);
 33     else
 34     if(((st *)x)->g!=((st *)y)->g)
 35     return (((st *)y)->g-((st *)x)->g);
 36     else
 37     if(((st *)x)->h!=((st *)y)->h)
 38     return (((st *)y)->h-((st *)x)->h);
 39     else
 40     if(((st *)x)->c!=((st *)y)->c)
 41     return (((st *)x)->c-((st *)y)->c);
 42     else
 43     return strcasecmp(((st *)x)->j,((st *)y)->j);
 44 
 45 }
 46 int main()
 47 {
 48     int n,t,k,i,j;
 49     char str[101],team[31][31],com[101],sw[101],cw[101],tw[101];
 50     cin>>n;
 51     getchar();
 52     while(n--)
 53     {
 54         st q[101];
 55         gets(str);
 56         cin>>t;
 57         getchar();
 58         ff.clear();
 59         for(i = 0; i < t ; i++)
 60         {
 61             gets(team[i]);
 62             ff[team[i]] = i;
 63             strcpy(q[ff[team[i]]].j,team[i]);
 64         }
 65         cin>>k;
 66         getchar();
 67         while(k--)
 68         {
 69             gets(com);
 70             int temp;
 71             for(i = 0 ; i < strlen(com) ; i++)
 72             {
 73                 if(com[i]!='#')
 74                 sw[i]=com[i];
 75                 else
 76                 {
 77                     temp = i;
 78                     break;
 79                 }
 80             }
 81             sw[temp] = '\0';
 82             q[ff[sw]].c++;
 83             int o1 = 0,o2 = 0;
 84             for(i = temp+1 ; i < strlen(com) ; i++)
 85             {
 86                 if(com[i]!='@')
 87                 tw[o1++] = com[i];
 88                 else
 89                 {
 90                     temp = i;
 91                     break;
 92                 }
 93             }
 94             tw[o1] = '\0';
 95             o1 = atoi(tw);
 96             for(i = temp+1 ; i < strlen(com) ; i++)
 97             {
 98                 if(com[i]!='#')
 99                 tw[o2++] = com[i];
100                 else
101                 {
102                     temp = i;
103                     break;
104                 }
105             }
106             tw[o2] = '\0';
107             o2 = atoi(tw);
108             int o3 = 0;
109             for(i = temp+1; i < strlen(com) ; i++)
110             cw[o3++] = com[i];
111             cw[o3]='\0';
112             q[ff[cw]].c++;
113             q[ff[sw]].h += o1;
114             q[ff[sw]].i += o2;
115             q[ff[cw]].h += o2;
116             q[ff[cw]].i += o1;
117             if(o2>o1)
118             {
119                 q[ff[cw]].d++;
120                 q[ff[sw]].f++;
121                 q[ff[cw]].b+=3;
122             }
123             else
124             if(o2<o1)
125             {
126                 q[ff[sw]].d++;
127                 q[ff[cw]].f++;
128                 q[ff[sw]].b+=3;
129             }
130             else
131             {
132                 q[ff[sw]].e++;
133                 q[ff[cw]].e++;
134                 q[ff[sw]].b++;
135                 q[ff[cw]].b++;
136             }
137         }
138         cout<<str<<endl;
139         for(i = 0 ; i < t ; i++)
140         q[i].g = q[i].h-q[i].i;
141         qsort((void *)q,t,sizeof(q[0]),cmp);
142         for(i = 0 ; i < t ; i++)
143         {
144             cout<<i+1<<") "<<q[i].j<<" "<<q[i].b<<"p, "<<q[i].c<<"g ("<<q[i].d<<"-"<<q[i].e<<"-"<<q[i].f<<"), "<<q[i].h-q[i].i<<"gd ("<<q[i].h<<"-"<<q[i].i<<")"<<endl;
145         }
146 
147         if(n!=0)
148         puts("");
149     }
150     return 0;
151 }

 

 

转载于:https://www.cnblogs.com/shangyu/archive/2012/07/25/2607813.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值