UVaOJ 10194 - Football(aka Soccer)
来源:互联网 发布:英克软件多少钱 编辑:程序博客网 时间:2024/05/21 00:48
AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 1. Elementary Problem Solving ::Sorting/Searching
Description
模拟足球小组赛的规则, 通过比赛记录, 计算出最后的 rank 及队伍的各项数据。
rank 规则(优先级从高到低):
- 分数最多者。
- 胜场最多者。
- 进丢球差最大者。
- 进球数最多者。
- 比赛场次少者。
- 队名字典序小者。
而一场比赛, 胜者得 3 分, 输者得 2 分。
Type
Sorting/Searching
Analysis
入门级的恶心模拟题。
注意队名是含有大小写字母的, 而字典序中大小写没有区别。
这就造成了字典序, 和 STL string 默认的小于号, 有细微的差别。
这细微的差别可能就是你无限 WA 的根源。
Solution
// UVaOJ 10194// Football(aka Soccer)// by A Code Rabbit#include <algorithm>#include <cctype>#include <cstdio>#include <iostream>#include <string>using namespace std;string ToLower(string);struct Team { string name; int point; int game; int win, tie, loss; int scored, against, difference; void Init() { point = game = win = tie = loss = scored = against = difference = 0; } bool operator<(Team another) const { if (this->point != another.point) return this->point > another.point; else if (this->win != another.win) return this->win > another.win; else if (this->difference != another.difference) return this->difference > another.difference; else if (this->scored != another.scored) return this->scored > another.scored; else if (this->game != another.game) return this->game < another.game; else return ToLower(this->name) < ToLower(another.name); }};string tournament;int t;Team team[32];int g;string team_name_1, team_name_2;int goals1, goals2;void Analyze(string team1, string team2, int goal1, int goal2);int main() { int tot_case; cin >> tot_case; cin.get(); while (tot_case--) { // Input. getline(cin, tournament); cin >> t; cin.get(); for (int i = 0; i < t; i++) { team[i].Init(); getline(cin, team[i].name); } cin >> g; cin.get(); // Input data and analyze data. for (int i = 0; i < g; i++) { getline(cin, team_name_1, '#'); cin >> goals1; cin.get(); cin >> goals2; cin.get(); getline(cin, team_name_2); team_name_1 = str1; team_name_2 = str2; Analyze(team_name_1, team_name_2, goals1, goals2); } // Rank. sort(team, team + t); // Output. printf("%s\n", tournament.c_str()); for (int i = 0; i < t; i++) { printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", i + 1, team[i].name.c_str(), team[i].point, team[i].game, team[i].win, team[i].tie, team[i].loss, team[i].difference, team[i].scored, team[i].against); } printf("%s", tot_case ? "\n" : ""); } return 0;}string ToLower(string str) { for (int i = 0; i < str.length(); i++) str[i] = tolower(str[i]); return str;}void Analyze(string team_name_1, string team_name_2, int goal1, int goal2) { Team* team1; Team* team2; for (int i = 0; i < t; i++) { if (team[i].name == team_name_1) team1 = &team[i]; if (team[i].name == team_name_2) team2 = &team[i]; } if (goal1 > goal2) { team1->point += 3; team1->win++; team2->loss++; } else if (goal1 < goal2) { team1->loss++; team2->win++; team2->point += 3; } else if (goal1 == goal2) { team1->point++; team1->tie++; team2->point++; team2->tie++; } /* team1 */ team1->game++; team1->scored += goal1; team1->against += goal2; team1->difference = team1->scored - team1->against; /* team2 */ team2->game++; team2->scored += goal2; team2->against += goal1; team2->difference = team2->scored - team2->against;}
- UVaOJ 10194 - Football(aka Soccer)
- 10194 - Football (aka Soccer)
- 10194 - Football (aka Soccer)
- 10194 - Football (aka Soccer)
- 10194 - Football (aka Soccer)
- 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 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)
- HDU 1573 中国剩余定理(有不互质情况)
- 【Windows核心编程】Windows核心编程 -- 线程基础
- 前端开发研究者网址
- 在IIS6中安装WebKnight的方法(iis防火墙)
- RFID防碰撞算法(三)
- UVaOJ 10194 - Football(aka Soccer)
- 使用ViewData 字典
- python 获取当前时间
- 进程与线程的区别
- hdu 1176(天上掉馅饼了)
- 浅学设计模式之建造者(Buildler Pattern)模式及在android中的应用
- 用一生去等一个约定
- Fatal error: Allowed memory size of 33554432 bytes exhausted
- Java基础加强---枚举