您的位置:首页 > 其它

UVA10194 Football (aka Soccer) 排序

2014-06-16 19:38 323 查看
说实话这题真心把我恶心着了, 还没敲过这么长的题。。。

自我感觉这题主要卡在输入格式, mark一下, 做了这么久。。。

#include<map>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAX 1000+10
#define min(a, b)   a < b ? a : b
using namespace std;
struct Team{
string na;
int sc, go, ag, play;
int win, tie, lost;
}t[MAX];
map<string, int> G;
bool cmp(Team x, Team y){
if (x.sc != y.sc)
return x.sc > y.sc;
if (x.win != y.win)
return x.win > y.win;
if ((x.go - x.ag) != (y.go - y.ag))
return (x.go - x.ag) > (y.go - y.ag);
if (x.go != y.go)
return x.go > y.go;
if (x.play != y.play)
return x.play < y.play;
for (int i = 0; i < min(x.na.length(), y.na.length()); i++){
if (isalpha(x.na.at(i)) && isalpha(y.na.at(i))){
if (x.na.at(i) != y.na.at(i))
return tolower(x.na.at(i)) < tolower(y.na.at(i));
}
else
return x.na.at(i) < y.na.at(i);
}
return x.na.length() < y.na.length();
}
void init(int k){
t[k].sc = t[k].go = t[k].ag = t[k].play = t[k].win= t[k].tie = t[k].lost = 0;
return ;
}
int atoi(string s){
int sum, len = s.size();
sum = 0;
for(int i = 0; i < len; i++)
sum = sum*10 + s[i]-'0';
return sum;
}
int main()
{
//freopen("input.cpp", "r", stdin);
int n, T, Case;
string t1, t2, tournament;
cin >> Case; getchar();
for(int j = 0; j < Case; j++){
if(j)   printf("\n");
G.clear();
getline(cin, tournament);
scanf("%d", &n); getchar();
for(int i = 0; i < n; i++){
getline(cin, t1);
G[t1] = i; t[i].na = t1;
init(i);
}
scanf("%d", &T);    getchar();
string tour, score; int s, e, k1, k2, x, y;
for(int i = 0; i < T; i++){
getline(cin, tour);
s = e = 0;
e = tour.find_first_of("#");
t1 = tour.substr(s, e-s);
s = tour.find_first_of("@");
score = tour.substr(e+1, s-e-1);
k1 = atoi(score);
e = tour.find_first_of("#", s);
score = tour.substr(s+1, e-s-1);
k2 = atoi(score);
t2 = tour.substr(e+1, tour.size()-e-1);
x = G[t1]; y = G[t2];
t[x].go += k1; t[x].ag += k2;
t[y].go += k2; t[y].ag += k1;
t[x].play++; t[y].play++;
if(k1 > k2){
t[x].win++; t[x].sc += 3;
t[y].lost++;
}
else if(k1 == k2){
t[x].tie++; t[x].sc++;
t[y].tie++; t[y].sc++;
}
else{
t[x].lost++;
t[y].win++; t[y].sc += 3;
}
}
sort(t, t+n, cmp);
cout << tournament << endl;
for(int i = 0; i < n; i++){
printf("%d) ", i+1);
cout << t[i].na;
printf(" %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",
t[i].sc, t[i].play, t[i].win, t[i].tie, t[i].lost, t[i].go-t[i].ag, t[i].go, t[i].ag);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva