UVA 10194 Football (aka Soccer)
来源:互联网 发布:soc软件品牌 编辑:程序博客网 时间:2024/05/16 00:24
题目
足球
分析
这题目不难但是很烦,按建议使用了结构体。
代码
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>char name1[35], name2[35];struct model{ char name[35]; int point, played, win, tie, loss, diff, scored, against;};int cmp(const struct model a, const struct model b){ int i; if (a.point >= b.point) { if (a.point > b.point) return 1; if (a.win >= b.win) { if (a.win > b.win) return 1; if (a.diff >= b.diff) { if (a.diff > b.diff) return 1; if (a.scored >= b.scored) { if (a.scored > b.scored) return 1; if (a.played <= b.played) { if (a.played < b.played) return 1; for (i = 0; i < strlen(a.name); i++) name1[i] = tolower(a.name[i]); for (i = 0; i < strlen(b.name); i++) name2[i] = tolower(b.name[i]); return strcmp(name1, name2) < 0; } } } } } return 0;}int main(void){ int i, j, n, t, g, g1, g2; struct model team[35], tmp; char tournament[105]; char goals1[5], goals2[5]; char buf[1005]; scanf("%d\n", &n); while (n--) { memset(team, 0, sizeof(team)); fgets(tournament, 105, stdin); scanf("%d\n", &t); for (i = 0; i < t; i++) { fgets(team[i].name, 35, stdin); team[i].name[strlen(team[i].name)-1] = '\0'; team[i].point = team[i].played = team[i].win = team[i].tie = team[i].loss = team[i].diff = team[i].scored = team[i].against = 0; } scanf("%d\n", &g); while (g--) { fgets(buf, 1005, stdin); for (i = 0; buf[i] != '#'; i++) name1[i] = buf[i]; name1[i++] = '\0'; for (j = 0; buf[i] != '@'; i++, j++) goals1[j] = buf[i]; goals1[j++] = '\0'; for (j = 0, i+= 1; buf[i] != '#'; i++, j++) goals2[j] = buf[i]; goals2[j++] = '\0'; for (j = 0, i+= 1; buf[i] != '\n'; i++, j++) name2[j] = buf[i]; name2[j++] = '\0'; for (i = 0; strcmp(name1, team[i].name) != 0; i++); for (j = 0; strcmp(name2, team[j].name) != 0; j++); g1 = atoi(goals1); g2 = atoi(goals2); team[i].played++, team[i].scored += g1, team[i].against += g2; team[j].played++, team[j].scored += g2, team[j].against += g1; if (g1 == g2) { team[i].tie++; team[j].tie++; } else if (g1 > g2) { team[i].win++; team[j].loss++; } else { team[i].loss++; team[j].win++; } } for (i = 0; i < t; i++) { team[i].point = 3*team[i].win + team[i].tie; team[i].diff = team[i].scored - team[i].against; } for (i = 0; i < t-1; i++) for (j = 0; j < t-1-i; j++) { /*printf("%d %d is compare-ing, result is %d\n", j, j+1, cmp(team[j], team[j+1]));*/ if (cmp(team[j], team[j+1]) == 0) { tmp = team[j]; team[j] = team[j+1]; team[j+1] = tmp; }} printf("%s", tournament); for (i = 0; i < t; i++) printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", i+1, team[i].name, team[i].point, team[i].played, team[i].win, team[i].tie, team[i].loss, team[i].diff, team[i].scored, team[i].against); if (n) printf("\n"); } return 0;}
0 0
- uva 10194 Football (aka Soccer)
- UVa 10194 - Football (aka Soccer)
- uva 10194 - Football (aka Soccer)
- UVA 10194 - Football (aka Soccer)
- uva 10194Football (aka Soccer)
- UVa 10194 - Football (aka Soccer)
- UVA 10194 Football (aka Soccer)
- uva 10194 - Football (aka Soccer)
- uva -- 10194 - Football (aka Soccer)
- UVA 10194 - Football (aka Soccer)
- UVa 10194 - Football (aka Soccer)
- UVA 10194 Football (aka Soccer)
- UVa:10194 - Football (aka Soccer)
- UVa 10194 - Football (aka Soccer)
- UVA - 10194 Football (aka Soccer)
- uva 10194 Football (aka Soccer)
- UVA 10194 Football (aka Soccer)
- UVA Football (aka Soccer)
- 树莓派Raspbian系统定制 - LXDE桌面系统定制 - 基本概念
- 解决svn执行cleanup出现failed–previous operation has not finished; run cleanup if it was interrupted 的错误
- Android地图添加标记和文字【代码片段】
- poj 1511 Invitation Cards(2遍spfa)
- 安卓开发第十二天
- UVA 10194 Football (aka Soccer)
- AIX 未开启AIO引起SQLPLUS登陆报错exec(): 0509-036
- Mysql基本检索数据方法大全
- Openstack magnum 简介
- ubuntu 14.04 降内核版本 -- 原因是 perf 版本与内核版本不配套
- mysql workbench 报 tables could not be fetched.
- moc
- Linux系统装有多个PHP的版本切换问题
- 数据库常用操作