UVa10194 - Football (aka Soccer)

题目地址:点击打开链接

C++代码:

#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.goals_scored!=B.goals_scored)
					return A.goals_scored>B.goals_scored;
				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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值