24h購物| | PChome| 登入
2013-06-18 07:56:39| 人氣515| 回應0 | 上一篇 | 下一篇

[UVA][格式] 10698 - Football Sort

推薦 0 收藏 0 轉貼0 訂閱站台

Problem C - Football Sort

Time Limit: 1 second

The Problem

Write a program, that given the fixtures of a football championship, outputs the corresponding classification following the format specified below. Win, draw and loss earn respectively three, one and zero points.

The criteria of classification are the number of points scored, followed by goal difference (goals scored minus goals suffered), and then scored goals. When more than one team have exactly the same number of points, goal difference, and scored goals, these are considered as having the same position in the classification.

The Input

The input will consist of a series of tests. Each test starts with a line containing two positive integers 28 ≥ T ≥ 1 and G ≥ 0. T is the number of teams and G is the number of games played. Follow then T lines, each containing the name of a squad. Squad names have up to 15 characters, and may only contain letters and dash characters ('-'). Finally the following G lines contain the score of each game. The scores are output with the following format: name of home team, number of goals scored by home team, a dash, number of goals scored by away team, and name of away team.

The input ends with a test case where T = G = 0 and should not be processed.

Output

The program shall output the classification tables corresponding to each input test separated by blank lines. In each table, the teams appear in order of classification, or alphabetically when they have the same position. The statistics of each team are displayed on a single line: team position, team name, number of points, number of games played, number of scored goals, number of suffered goals, goal difference, and percentage of earned points, when available. Note that if several teams have are in a draw, only the position of the first is printed. Fields shall be formatted and aligned as shown in the sample output.

Sample input

6 10
tA
tB
tC
td
tE
tF
tA 1 - 1 tB
tC 0 - 0 td
tE 0 - 0 tA
tC 0 - 0 tB
td 0 - 0 tE
tA 0 - 0 tC
tB 0 - 0 tE
td 0 - 0 tA
tE 0 - 0 tC
tB 0 - 0 td
2 2
Botafogo
Flamengo
Botafogo 3 - 2 Flamengo
Flamengo 2 - 3 Botafogo
5 10
tA
tB
tC
tD
tE
tA 0 - 0 tB
tC 0 - 0 tD
tE 0 - 0 tA
tC 0 - 0 tB
tD 0 - 0 tE
tA 0 - 0 tC
tB 0 - 0 tE
tD 0 - 0 tA
tE 0 - 0 tC
tB 0 - 0 tD
3 2
Quinze-Novembro
Flamengo
Santo-Andre
Quinze-Novembro 6 - 0 Flamengo
Flamengo 0 - 2 Santo-Andre
0 0

Sample output

 1.              tA   4   4   1   1   0  33.33
                 tB   4   4   1   1   0  33.33
 3.              tC   4   4   0   0   0  33.33
                 td   4   4   0   0   0  33.33
                 tE   4   4   0   0   0  33.33
 6.              tF   0   0   0   0   0    N/A

 1.        Botafogo   6   2   6   4   2 100.00
 2.        Flamengo   0   2   4   6  -2   0.00

 1.              tA   4   4   0   0   0  33.33
                 tB   4   4   0   0   0  33.33
                 tC   4   4   0   0   0  33.33
                 tD   4   4   0   0   0  33.33
                 tE   4   4   0   0   0  33.33

 1. Quinze-Novembro   3   1   6   0   6 100.00
 2.     Santo-Andre   3   1   2   0   2 100.00
 3.        Flamengo   0   2   0   8  -8   0.00

排序按照積分、得分數差、得分數 由大排到小。

相同的時候, 按照隊名字典順序排, 字串比較不區分大小寫。

用內建似乎會拿到 CE,用動打一個也不難的。

至於那個積分比率,原來是 得到總積分/(3*場數)

#include <stdio.h>
#include <map>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
int strcmpnocase(string a, string b) {
for(int i = 0; i < a.length(); i++)
if(a[i] >= 'a')
a[i] = a[i]-32;
for(int i = 0; i < b.length(); i++)
if(b[i] >= 'a')
b[i] = b[i]-32;
return a.compare(b);
}
struct E {
string name;
int f1, f2, f3, f4, f5;
double f6;
bool operator<(const E &a) const {
if(f1 != a.f1)
return f1 > a.f1;
if(f5 != a.f5)
return f5 > a.f5;
if(f3 != a.f3)
return f3 > a.f3;
return strcmpnocase(name, a.name) < 0;
}
bool operator==(const E &a) const {
return f1 == a.f1 && f5 == a.f5 && f3 == a.f3;
}
};
int main() {
int T, G;
int i, cases = 0;
char s[1005][105], a[105], b[105];
while(scanf("%d %d", &T, &G) == 2) {
if(T == 0)
break;
if(cases) puts("");
cases++;
map<string, int> R;
for(i = 0; i < T; i++) {
scanf("%s", s[i]);
R[s[i]] = i;
}
int field[1005][4] = {};
int sa, sb;
while(G--) {
scanf("%s %d - %d %s", a, &sa, &sb, b);
int x = R[a], y = R[b];
field[x][0] += (sa == sb) ? 1 : ((sa > sb) ? 3 : 0);
field[x][1]++, field[x][2] += sa, field[x][3] += sb;
field[y][0] += (sa == sb) ? 1 : ((sb > sa) ? 3 : 0);
field[y][1]++, field[y][2] += sb, field[y][3] += sa;
}
E D[1005];
for(i = 0; i < T; i++) {
D[i].name = s[i];
D[i].f1 = field[i][0], D[i].f2 = field[i][1];
D[i].f3 = field[i][2], D[i].f4 = field[i][3];
D[i].f5 = field[i][2]-field[i][3];
D[i].f6 = field[i][0]*100.0 / (field[i][1]*3.0);
}
sort(D, D+T);
char buf[100];
for(i = 0; i < T; i++) {
if(D[i].f2 == 0)
sprintf(buf, " N/A");
else
sprintf(buf, "%6.2lf", D[i].f6);
if(i == 0 || !(D[i] == D[i-1])) {
printf("%2d.%16s%4d%4d%4d%4d%4d %s\n", i+1,
D[i].name.c_str(), D[i].f1, D[i].f2, D[i].f3, D[i].f4, D[i].f5, buf);
} else {
printf(" %16s%4d%4d%4d%4d%4d %s\n",
D[i].name.c_str(), D[i].f1, D[i].f2, D[i].f3, D[i].f4, D[i].f5, buf);
}
}
}
return 0;
}
 

台長: Morris
人氣(515) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][dp] 10448 - Unique World
此分類上一篇:[UVA][math] 10493 - Cats, with or without Hats

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文