⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2925.cpp

📁 acm pku 2925 源代码+部分注释
💻 CPP
字号:
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
#define MAXN 60
//Variables Declarations
	int iScenario,p,r,g;	//p:人数 r:比赛回数  g:当前回比赛数目 
	char name[MAXN][MAXN];
	int point[MAXN],point_temp[MAXN],dot[MAXN];
//Functions Declarations
	void INPUT();
	void WORK();
	void OUTPUT(int i);
	void EXCHANGE(int i,int j);
	
int main()
{
	int i;
	scanf("%d",&iScenario);
	for(i=1;i<=iScenario;++i)
	{
		INPUT();	
		WORK();
		OUTPUT(i);
	}
	return 0;
}

void INPUT()
{
	int i;
	scanf("%d %d",&p,&r);
	getchar();
	for(i=1;i<=p;++i)
	{
		point[i]=0;
		dot[i]=0;	
	}
	for(i=1;i<=p;++i)
		cin.getline(name[i],MAXN);	//okay

	return;	
}

void WORK()
{
	int i,j,k,score1,score2,temp1,temp2;
	int maxpoint,maxdot;
	char chtemp;
	for(i=1;i<=r;++i)
	{
		maxpoint=0;
		scanf("%d",&g);
		for(j=1;j<=p;++j)
			point_temp[j]=0;
		for(j=1;j<=g;++j)
		{
			scanf("%d %c %d",&score1,&chtemp,&score2);
			for(k=1;k<=p;++k)
			{
				scanf("%d %c %d",&temp1,&chtemp,&temp2);
				if(score1==score2)
				{
					if(temp1==temp2)
					{
						point[k]+=1;
						point_temp[k]+=1;
					}
					if(score1==temp1 && score2==temp2)
					{
						point[k]+=2;	
						point_temp[k]+=2;
					}
				}	
				else if(score1<score2)
				{
					if(temp1<temp2)
					{
						++point[k];
						++point_temp[k];
						if(score1==temp1 && score2==temp2)
						{
							point[k]+=2;
							point_temp[k]+=2;
						}
					}	
				}
				else if(score1>score2)
				{
					if(temp1>temp2)
					{
						++point[k];
						point_temp[k]+=1;
						if(score1==temp1 && score2==temp2)
						{
							point[k]+=2;
							point_temp[k]+=2;
						}
					}	
				}
				if(point_temp[k] > maxpoint) maxpoint=point_temp[k];
			}
		}
		for(k=1;k<=p;++k)
			if(point_temp[k]==maxpoint)
				++dot[k];
	}	

	int pos;
	for(i=1;i<=p;++i)	//每次找出最大的
	{
		maxpoint=-1;
		maxdot=-1;
		// 一定要-1,因为可能出现point=0的情况!!!! 
		for(j=i;j<=p;++j)
		{
			if(point[j] > maxpoint) 
			{
				maxpoint=point[j];
				maxdot=dot[j];
				pos=j;
			}
			else if (point[j]==maxpoint && dot[j] > maxdot)
			{
				maxdot=dot[j];
				pos=j;
			}
		}
		for(j=pos;j>=i+1;--j)
		{
			EXCHANGE(j,j-1);
		}
		
	} 
	return;	
}

void EXCHANGE(int i,int j)
{
	int temp;
	char chtemp[MAXN];
	temp=point[i]; point[i]=point[j]; point[j]=temp;
	temp=dot[i]; dot[i]=dot[j]; dot[j]=temp;
	strcpy(chtemp,name[i]); strcpy(name[i],name[j]); strcpy(name[j],chtemp);
	return;	
}
void OUTPUT(int iCase)
{
	int i;
	printf("Scenario #%d:\n",iCase);
	for(i=1;i<=p;++i)
		printf("%d %d %s\n",point[i],dot[i],name[i]);
	printf("\n");
	return;	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -