Cued In(水题)

Description

Snooker is a cue sport played by two players on a rectangular table. The players take turns topot a series of balls of varying colours, where each colour represents a distinct point value forpotting the ball.

A player may pot any ball on the table initially, however any subsequent shots must follow apattern: if the previous ball was red, the next ball must be another colour; otherwise, if there arestill red balls left, the next ball must be red.

Balls of any colour other than red are initially replaced on the table every time they are potted,and may be used again to score more points. The balls stop being replaced once all of the redballs have been potted.

The values of each coloured ball are:

Colour red yellow green brown blue pink black

Value     1      2         3        4       5      6      7

Snooker players are respected universally for their prowess in mental arithmetic. One sweepingglance across the table is enough to tell an experienced contestant how much they could score.For newer players, however, this is a challenge. Write a program to help calculate a score for agiven list of balls remaining on the table.

Input

• one line containing the integers N (1 ≤ N ≤ 21), the number of balls remaining on thetable

.• N further lines, each containing the colour of one of the balls on the table.

The list of balls will not be ordered in any way and will contain at most one of each of yellow,green, brown, blue, pink and black.

Output

Output the largest possible score the player can make.

Sample Input

5

red

black

pink

red

red

Sample Output

37

Sample Input

3

blue

black

pink

Sample Output

18

Sample Input

8

yellow

green

brown

red

red

red

red

red

Sample Output

34

Sample Input

2

red

red

Sample Output

1

题解:每当打完一个红球,必须打一个彩球,否则结束。打完红球打彩球,彩球加分后仍会出现在桌面上。

代码如下:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
	int a[8]={0},t,s=0;
	cin>>t;
	int tt=t;
	while(t--)
	{
		char b[10];
		cin>>b;
		if(strcmp(b,"red")==0)
			s++;
		if(strcmp(b,"yellow")==0)
			a[2]++;
		if(strcmp(b,"green")==0)
			a[3]++;
		if(strcmp(b,"brown")==0)
			a[4]++;
		if(strcmp(b,"blue")==0)
			a[5]++;
		if(strcmp(b,"pink")==0)
			a[6]++;
		if(strcmp(b,"black")==0)
			a[7]++;
	}
	int max=1,sum=0;
	for(int i=2;i<=7;i++)
	{
		sum+=i*a[i];
		if(a[i]!=0&&max<i)
			max=i;
	}
	sum+=s*max+s;
	if(s==tt)
		cout<<"1"<<endl;
	else
		cout<<sum<<endl;
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值