hdoj 1225 football sorce(尝试了50次的水题)

思路:简单题,细节很多;直接给代码;

#include   
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
struct node
{
	char name[1010];
	int win;
	int lose;
	int point;

}team[1010];
int judge(int a, int b)
{
	if (a>b)
		return 3;
	else if (a == b)
		return 1;
	else
		return 0;
}

bool cmp(node a, node b)
{
	if (a.point == b.point)
	{
		if ((a.win - a.lose) == (b.win - b.lose))
		{
			if (a.win == b.win)
				return a.name[0] < b.name[0];			//这里就是我被wa了30次的原因。。。。少写了【0】;
			else
				return a.win > b.win;
		}
			
		else
			return a.win - a.lose>b.win - b.lose;
	}
	else
		return a.point>b.point;
}
int main()
{
	int n;
	char team1[1010], team2[1010];
	int p, q;
	int i;
	int x;
	int t;
	int z1, z2;

	while (scanf("%d%*c", &n) != EOF)
	{

		t = n * (n - 1);
		x = 0;
		while (t--)
		{
			z1 = z2 = -1;

			scanf("%s VS %s %d:%d", team1, team2, &p, &q);
			for (i = 0; i < x; i++)
			{
				if (strcmp(team1, team[i].name) == 0)
					z1 = i;
				if (strcmp(team2, team[i].name) == 0)
					z2 = i;
				if (z1 != -1 && z2 != -1)
					break;


			}
			if (z1 != -1)										//比较字符串的时候也有技巧,我这样的方法比较简单好理解,也不容易错
			{

				team[z1].point += judge(p, q);
				team[z1].win += p;
				team[z1].lose += q;


			}
			if (z2 != -1)
			{
				team[z2].point += judge(q, p);
				team[z2].win += q;
				team[z2].lose += p;
			}
			if (z1 == -1)
			{
				memset(team[x].name, 0, sizeof(team[x].name));
				team[x].point = 0;
				team[x].lose = 0;
				team[x].win = 0;
				strcpy(team[x].name, team1);
				team[x].point += judge(p, q);
				team[x].lose += q;
				team[x].win += p;
				x++;
			}
			if (z2 == -1)
			{
				memset(team[x].name, 0, sizeof(team[x].name));
				team[x].point = 0;
				team[x].lose = 0;
				team[x].win = 0;
				strcpy(team[x].name, team2);
				team[x].point += judge(q, p);
				team[x].lose += p;
				team[x].win += q;
				x++;
			}

		}
		sort(team, team + x, cmp);
		for (i = 0; i


你可能感兴趣的:(模拟+water~~)