UVa 10194 WA,谢谢谢谢
本帖最后由 leizh007 于 2013-10-11 22:56:04 编辑 题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=13&problem=1135&mosmsg=Submission+received+with+ID+12483398
不知道错哪儿了,给个错误的例子就行,谢谢谢谢
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cctype>
using namespace std;
const int maxsize=10000;
class Team
{
public:
string team_name;
string team_name_tolower;
int played_num;
int total_points_earned;
int wins;
int ties;
int losses;
int goal_difference;
int goals_scored;
int goals_against;
Team():total_points_earned(0),wins(0),ties(0),losses(0),goal_difference(0),goals_scored(0),goals_against(0),played_num(0){}
};
bool cmp(const Team &A,const Team &B)
{
if(A.total_points_earned!=B.total_points_earned)
return A.total_points_earned>B.total_points_earned;
else
{
if(A.wins!=B.wins)
return A.wins>B.wins;
else
{
if(A.goal_difference!=B.goal_difference)
return A.goal_difference>B.goal_difference;
else
{
if(A.played_num!=B.played_num)
return A.played_num<B.played_num;
else
{
return A.team_name_tolower<B.team_name_tolower;
}
}
}
}
}
int main()
{
map<string,int> index;
int n;
cin>>n;
getchar();
while(n--)
{
index.clear();
string tournament;
getline(cin,tournament);
int team_num;
Team T[maxsize];
cin>>team_num;
getchar();
int i,j;
for(i=0;i<team_num;++i)
{
getline(cin,T[i].team_name);
index.insert(make_pair(T[i].team_name,i));
T[i].team_name_tolower=T[i].team_name;
for(j=0;j<T[i].team_name_tolower.size();++j)
T[i].team_name_tolower[j]=tolower(T[i].team_name_tolower[j]);
}
int tournament_num;
cin>>tournament_num;
getchar();
while(tournament_num--)
{
string one_tournament;
getline(cin,one_tournament);
int goals1,goals2;
i=0;
j=i;
while(one_tournament[j]!='#')
++j;
string team_name_1(one_tournament,i,j-i);
i=j+1;
j=i;
while(one_tournament[j]!='@')
++j;
string goal_1(one_tournament,i,j-1);
goals1=atoi(goal_1.c_str());
i=j+1;
j=i;
while(one_tournament[j]!='#')
++j;
string goal_2(one_tournament,i,j-1);
goals2=atoi(goal_2.c_str());
i=j+1;
string team_name_2(one_tournament,i,one_tournament.size()-i);
int team_1_num=index[team_name_1];
int team_2_num=index[team_name_2];
++T[team_1_num].played_num;
++T[team_2_num].played_num;
if(goals1>goals2)
{
++T[team_1_num].wins;
++T[team_2_num].losses;
}
else if(goals1<goals2)
{
++T[team_2_num].wins;
++T[team_1_num].losses;
}
else
{
++T[team_1_num].ties;
++T[team_2_num].ties;
}
T[team_1_num].goals_scored+=goals1;
T[team_1_num].goals_against+=goals2;
T[team_2_num].goals_scored+=goals2;
T[team_2_num].goals_against+=goals1;
}
for(i=0;i<team_num;++i)
{
T[i].total_points_earned=T[i].wins*3+T[i].ties;
T[i].goal_difference=T[i].goals_scored-T[i].goals_against;
}
sort(T,T+team_num,cmp);
cout<<tournament<<endl;
for(i=0;i<team_num;++i)
cout<<i+1<<") "<<T[i].team_name<<" "<<T[i].total_points_earned<<"p, "<<T[i].played_num<<"g ("
<<T[i].wins<<"-"<<T[i].ties<<"-"<<T[i].losses<<"), "<<T[i].goal_difference<<"gd ("
<<T[i].goals_scored<<"-"<<T[i].goals_against<<")"<<endl;
if(n!=0)
cout<<endl;
}
return 0;
}