UVA - 10194 Football (aka Soccer) 多种排序

来源:互联网 发布:linux 复制整行 编辑:程序博客网 时间:2024/05/17 22:16

题目大意:有N场大赛,M支队伍,每场大赛里面有K场比赛,比赛的得分按照:如果赢的话得3分,平局得1分,输了得0分,先要求按这种格式输出:

[a]) Team_name [b]p, [c]g ([d]-[e]-[f]), [g]gd ([h]-[i])[a] = 队伍序,[b] = 总得分,[c] = 比赛了几场,[d] = 赢了几场,[e] = 平局了几场,[f] = 输了几场,[g] = 净进球数,[h] = 总进球数,[i] = 丢了几个球输出时要严格排序,按以下顺序排序
  1. 总得分
  2. 赢的场数
  3. 净进球数
  4. 总进球数
  5. 比赛次数少
  6. 队名的字典序(这个字典序要将队名转换成小写再排序)
解题思路:处理比较麻烦,思路还是很简单的,就不详写了
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define maxn 105struct teams{char name[35];int a,b,c,d,e,f,g,h,i;};teams t[35];void UTL(char st[]) {int len = strlen(st);for(int i = 0; i < len; i++)if(st[i] >= 'A' && st[i] <= 'Z')st[i] = st[i] + 32;}int cmp(const void *p1, const void *p2) {struct teams *a =(struct teams*) p1;struct teams *b =(struct teams*) p2;if( a->b != b->b) return a->b < b->b;if( a->d != b->d )return a->d < b->d;if( (a->h - a->i) != (b->h - b->i))return a->h - a->i < b->h - b->i;if(a->h != b->h)return a->h < b->h;if(a->c != b->c)return a->c > b->c;char ta[50],tb[50];strcpy(ta,a->name);strcpy(tb,b->name);UTL(ta);UTL(tb);return strcmp(ta,tb);}int main() {int test,N,G;char title[300];scanf("%d\n",&test);while(test--) {gets(title);scanf("%d\n",&N);for(int i = 0; i < N; i++) {gets(t[i].name);t[i].a = t[i].b = t[i].c = t[i].d = t[i].e = t[i].f = t[i].g = t[i].h = t[i].i = 0;}scanf("%d\n",&G);char temp[300];char team1[35],team2[35];int s1,s2;int len;for(int i = 0; i < G; i++){gets(temp);len = strlen(temp);int j,cnt = 0;for(j = 0; temp[j] != '#'; j++)team1[cnt++] = temp[j];team1[cnt] = '\0';int num = 0;for(j++; temp[j] != '@'; j++)num = num * 10 + temp[j] - '0';s1 = num;num = 0;for(j++; temp[j] != '#'; j++)num = num * 10 + temp[j] - '0';s2 = num;cnt = 0;for(j++; j < len; j++)team2[cnt++] = temp[j];team2[cnt] = '\0';for(int k = 0; k < N; k++) {if(strcmp(t[k].name,team1) == 0) {if(s1 > s2) {t[k].d++;t[k].b += 3;}if(s1 == s2) {t[k].e++;t[k].b += 1;}if(s1 < s2) t[k].f++;t[k].c++;t[k].h += s1;t[k].i += s2;}if(strcmp(t[k].name,team2) == 0) {if(s2 > s1) {t[k].d++;t[k].b += 3;}if(s1 == s2) {t[k].e++;t[k].b += 1;}if(s2 < s1)t[k].f++;t[k].c++;t[k].h += s2;t[k].i += s1;}}}qsort(t,N,sizeof(t[0]),cmp);printf("%s\n",title);for(int i = 0; i < N; i++)printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i+1,t[i].name,t[i].b,t[i].c,t[i].d,t[i].e,t[i].f,t[i].h-t[i].i,t[i].h,t[i].i);if(test)printf("\n");}return 0;}


0 0
原创粉丝点击