PGA Tour Prize Money(UVa207)

PGA Tour Prize Money

A PGA (Professional Golf Association) Tour event is a golf tournament in which prize money is awarded to the best players. The tournament is broken into four rounds of 18 holes apiece. All players are eligible to
play the first two rounds. Only those with the best scores from those 36 holes ``make the first cut" to play the final two rounds and qualify for prize money. Players with the best 72-hole aggregate scores (the lowest scores) earn prize money.

You must write a program to determine how the total prize money (called the tournament ``purse") is to be allocated for a tournament. Specifications are as follows.

1)All players will play at least two 18-hole rounds (36 holes in all) unless they are disqualified for some reason.2)Any player who is disqualified stops playing at the time of the disqualification. Players who are disqualified during the first two rounds are ineligible to make the cut. Players who are disqualified during either of the last two rounds are ineligible to
win prize money.3)At the end of the first two rounds, the field of players is cut to the 70 players with the lowest 36-hole scores plus ties. So if 10 players are tied for 70th place, then 79 players make the 36-hole cut. Players who do not make the 36-hole cut are eliminated
from the playing field and do not win any prize money.4)The players who do make the 36-hole cut play an additional 36 holes (two 18-hole rounds) and are paid a percentage of the total prize money depending on their 72-hole aggregate score. The lower the score, the more prize money a player wins.5)Players are paid percentages of the the tournament purse according to their final standings. For example, if the tournament purse were $1,000,000 and the winner's share were 18%, the winner would earn $180,000.6)There will be only one winner of this tournament. (In an actual golf tournament, when there is a tie for the low 72-hole score, there is be a play-off among the tied players. We will ignore that situation.)7)There may be a tie for any or all of the positions between 2 and 70. If there is a tie among n players for position k, the money designated for positions k through n + k - 1 is pooled and allocated equally among
the tied players. For example, using the sample data given later, if there were a tie for second place between two golfers, they would each win $88,000 [(10.8% + 6.8%)/2 = 8.8% * $1,000,000]. If there were a three-way tie, all three golfers would get $74,666.67
[(10.8% + 6.8% + 4.8%)/3 = 7.46667% * $1,000,000]. The extra penny is ignored.8)If disqualification reduces the field to less than 70 players, the money for the last and any other places not covered is not allocated. For example, if exactly 70 players make the cut but three of them are disqualified, then the tournament simply pays
67 places.9)Amateur golfers may play in professional tournaments but can win no money. Any prize money ``won" by an amateur is allocated to the next lower position. For example, if an amateur has placed third in a tournament, then third place money goes to the fourth
place finisher, and fourth place money goes to the fifth place finisher, etc.10)Only the low 70 non-amateur places and ties earn prize money. For example, if 75 players make the 36-hole cut, it is possible for 5 of them not to earn prize money, assuming none of the players making the cut are amateurs.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also
a blank line between two consecutive inputs.


The input file is broken into two segments. The amount of the tournament purse and the percentages for all the 70 places are stored in the first segment of the input file. This segment contains exactly 71 lines,
which are formatted as follows.

Line 1: 		 Total value of the purse

		 Line 2: 		 Percentage of the purse designated for first place

		 Line 3: 		 Percentage of the purse designated for second place

		 ...

		 Line71: 		 Percentage of the purse designated for 70th place

All entries in the first 71 file lines can be read as real numbers. All percentages are given to four decimal places. Assume the percentages are correct and sum to 100%. A partial example of the first segment of
the input file is shown in the sample input section below.

The second segment of the input file contains the players' names and their respective scores for the four rounds. There is a maximum of 144 players. A first line contains the number of players and then one more
line for each one of them, with the format as follows (see a partial example in the sample input section).

Characters 1-20:   		   Player name

		 Characters 21 23:  		   Round 1 score (first 18 holes)

		 Characters 24-26:  		   Round 2 score (second 18 holes)

		 Characters 27-29:  		   Round 3 score (third 18 holes)

		 Characters 30-32:  		   Round 4 score (fourth 18 holes)

Any player who has an asterisk `*' at the end of his last name is an amateur. All players who are not disqualified will have four 18-hole scores listed. (Even though in an actual tournament, players who do not make
the cut do not get to play the last two rounds of the tournament, for the purposes of this program all players who are not disqualified will have four 18-hole scores listed.) A player who is disqualified during a round will have a score on that round shown
as `DQ'. That player will have no additional scores for the tournament. Assume that at least 70 players will make the 36-hole cut. The end of input is denoted by end-of-file.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

Output from this program consists of names of all players who made the 36-hole cut, their finish positions (with the letter ``T" after the numeric value representing the finish position if there is a money
sharing for that position, that means two or more NON-AMATEUR players with the same score, and all of them earning money), scores for each round, total scores, and the amounts of money won. Print the money won by a player only if the player gets a prize (even
if the prize is $0.00). Disqualified players are listed at the bottom with scores of DQ placed in the ``TOTAL" column. No player who failed to make the 36-hole cut is listed in the output. Each column of output should be formatted and labelled
appropriately. The dollar amounts should be correct to two decimal places. In case of tie order the players by rounds completed and by total shots. If there's still a tie, order them in alphabetical order.
A partial example of the output file (not corresponding to the sample input) is show in the sample output section.

Sample Input

1

1000000.00
18.0000
10.8000
6.8000
4.8000
...
0.2020
0.2000
140
WALLY WEDGE          70 70 70 70
SANDY LIE            80 DQ
SID SHANKER*         90 99 62 61
...
JIMMY ABLE           69 73 80 DQ

Sample Output

Player Name          Place     RD1  RD2  RD3  RD4  TOTAL     Money Won
-----------------------------------------------------------------------
WALLY WEDGE          1         70   70   70   70   280       $180000.00
HENRY HACKER         2T        77   70   70   70   287       $ 88000.00
TOMMY TWO IRON       2T        71   72   72   72   287       $ 88000.00
BEN BIRDIE           4         70   74   72   72   288       $ 48000.00
NORMAN NIBLICK*      4         72   72   72   72   288
...
LEE THREE WINES      71        99   99   99   98   395       $  2000.00
JOHNY MELAVO         72        99   99   99   99   396
JIMMY ABLE                     69   73   80        DQ

EDDIE EAGLE 71 71 DQ

找不到测试样例,就自己写了一个样例生成器。

样例生成器代码:

#include<cstdio>
#include<cstring>
#include<String>
#include<cstdlib>
#include<ctime>
using namespace std;


int main()
{
	freopen("input5_10.txt", "w", stdout);
	srand(time(NULL));
	char firstname[20][10] = {"James", "John", "David", "Daniel", "Jane", "Mary", "Elizabeth", "Ann", "Sarah", "Catherine",
							"Smith", "Miller", "Johnson", "Brown", "Jones", "Williams", "Brook", "Churchill", "Hill", "Lake"};
	char lastname[20][10] = {"Ailsa", "Aime", "Alice", "Alina", "Allison", "Barbara", "Beata", "Beatrice", "Becky", "Betty", 
							"Candice", "Carina", "Carmen", "Carol", "Caroline", "Demi", "Diana", "Dolore", "Donna", "Doris"};
	printf("1\n\n");
	printf("2485000.00\n\n");						
	for(int i=0; i<70; i++)
	{
		printf("%.4lf\n", (70-i)*100.0/2485);
	}
	printf("140\n");

	for(int i=0; i<140; i++)
	{
		char s[22];
		strcpy(s, firstname[rand()%20]);
		strcat(s, " ");
		strcat(s, lastname[rand()%20]);
		if(rand()%10<2) strcat(s, "*");
		else strcat(s, " ");
		for(int i=strlen(s); i<=19; i++) strcat(s, " ");
		printf("%s", s);
		
		
		for(int j=0; j<4; j++)
		{
			if(rand()%40==0) 
			{
				printf("DQ\t");
				break;
			}
			else
			{
				printf("%d\t", rand()%100);
			}
		}
		printf("\n");
	}
	
	
	
}


下面是我自己写的代码,已经找出了很多细节错误并且改掉了,这道题特别锻炼我注意细节的能力。

代码:

#include<cstdio>
#include<cstring>

using namespace std;

struct player_information 
{
	char name[22];
	int isamateur;//是否业余 
	int isparallel;//是否并列 
	int place;	//-1为DQ 
	int RD[4];	//-1为DQ 
	int total;	//99999为DQ 
	double money; 
}player[150];
int numofplayer;
int ranking[150];//包括业余选手的排名 
int prizeranking[150];//不包括业余选手的排名 

double moneypercentage[70]; //每一名获奖占总金额的比值*100 
double totalmoney;//总奖金 

//读取数据并装入player数组 
void read_data()
{
	scanf("%lf", &totalmoney);
	for(int i=0; i<70; i++) scanf("%lf", &moneypercentage[i]);
	
	scanf("%d", &numofplayer);
	char firstname[10],lastname[10],s[22];
	char score[10];
	for(int i=0; i<numofplayer; i++)
	{
		scanf("%s %s", firstname, lastname);
		if(lastname[strlen(lastname)-1]=='*') player[i].isamateur=1;
		
		strcpy(s, firstname);
		strcat(s, " ");
		strcat(s, lastname);
		for(int j=strlen(s); j<=17; j++) strcat(s, " ");
		strcpy(player[i].name, s);
		
		player[i].money=0;
		for(int j=0; j<4; j++)
		{
			scanf("%s", score);
			if(score[0]=='D') {player[i].RD[j]=-1; player[i].total=99999;break;}
			else sscanf(score, "%d", &player[i].RD[j]);
			player[i].total += player[i].RD[j];
		}
		player[i].isparallel=0;
		 
	}
	
}

//打印结果 
void print()
{
	int DQ;
	int i;
	printf("Player Name\t\tPlace\tRD1\tRD2\tRD3\tRD4\tTOTAL\tMoney Won\n");
	printf("-----------------------------------------------------------------------\n");
	for(int k=0; k<numofplayer; k++)
	{
		i = ranking[k];
		DQ = 0;
		printf("%s", player[i].name);
	//	printf("%s", player[i].isamateur ? "\t业余" : "\t");
		if(player[i].place != -1) printf("\t%d", player[i].place);
		else printf("\t");
		if(player[i].place != -1)
		printf("%c", (player[i].isparallel==1 ? 'T' : ' '));
		for(int j=0; j<4; j++) 
		{
			printf("\t");
			if(player[i].RD[j] == -1) DQ = 1;
			if(DQ==0)	printf("%d", player[i].RD[j]);
		}
		if(player[i].total != 99999)
		printf("\t%d", player[i].total);
		else printf("\tDQ");
			if(player[i].money != -1) printf("\t$%.2lf", player[i].money); 
		printf("\n");
	}
	
	/*
	printf("Ranking:\n");
	for(int i=0; i<numofplayer; i++)
	{
		printf("%d\n", ranking[i]);
	}
	printf("PrizeRanking:\n");
	for(int i=0; i<numofplayer; i++)
	{
		printf("%d\n", prizeranking[i]);
	}
	printf("moneypercentage:\n");
	for(int i=0; i<70; i++)
		printf("%lf\n", moneypercentage[i]);
	printf("\n\n\n");
	*/
}

//data_processing的子函数 
//用于排序,就是给ranking数组赋值 
void rank()
{
	for(int i=0; i<numofplayer; i++)
	{
		ranking[i] = i;
	}
	int minp;
	for(int i=0; i<numofplayer; i++)
	{
		minp = i;
		for(int j=i+1; j<numofplayer; j++)
		{
			if(player[ranking[j]].total<player[ranking[minp]].total) minp = j;
			
		}
		if(minp != i)
		{
			int temp = ranking[minp];
			ranking[minp] = ranking[i];
			ranking[i] = temp;
		}
		player[ranking[i]].place = i+1;
		player[ranking[minp]].place = minp+1;
			
			
		if(i>=1 && player[ranking[i]].total == player[ranking[i-1]].total)//标记是否并列 
		{
			player[ranking[i]].isparallel=player[ranking[i-1]].isparallel=1;
			player[ranking[i]].place = player[ranking[i-1]].place;
		}
		
		if(player[ranking[i]].total==99999) player[ranking[i]].place = -1;
		
	}
}

//data_processing的子函数 
//用于非业余选手的排序和分配奖金 
void money()
{
	
	
	memset(prizeranking, 0, sizeof(prizeranking));
	for(int i=0, j=0; j<numofplayer; i++, j++)//给prizeranking[] 赋值 
	{
		while(player[ranking[j]].isamateur) 
		{
			player[ranking[j]].money = -1;
			j++;
		}
		prizeranking[i]=ranking[j]; 
	}
	
	for(int i=0; i<numofplayer; i++)
	{
		if(i<70) 
		player[prizeranking[i]].money = totalmoney * moneypercentage[i]/100;
		else
		player[prizeranking[i]].money = -1;
	}
	
	
	int numofparallel = 1;
	
	for(int i=1; ; i++)
	{
		if(i>=70 && numofparallel==1) break;
		
		
		
		
		if(player[prizeranking[i]].total==player[prizeranking[i-1]].total)
		{
			numofparallel++;
		}
		else if(numofparallel>=2)
		{
			double money = 0;
			for(int j=1; j<=numofparallel; j++)
			{
				money += ((player[prizeranking[i-j]].money+1)<0.000001 ? 0 : player[prizeranking[i-j]].money);
			}
			money /= numofparallel;
			for(int j=1; j<=numofparallel; j++)
			{
				player[prizeranking[i-j]].money = money;
			}
			
			numofparallel=1;
		}
		
		
	}
	
	
}

//数据处理,出结果 
void data_processing()
{
	rank();
	money();
	 
}


int main()
{
	int T;
	freopen("input5_10.txt", "r", stdin);
	freopen("output5_10.txt", "w", stdout);//这里为了方便调试我的输入输出都做了重定向 
	scanf("%d", &T);
	while(T--)
	{
		read_data(); 
		data_processing();
		print();
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值