GOLF CROQUET
题目描述
In golf croquet doubles, two teams of 2 play each other. Each player has their own ball which they hit when it is their turn. A turn comprises one hit of the ball.
There are 6 hoops which are each played twice, once in each direction, in a prescribed order.
A point is scored by the first team to “make” the current hoop. To make a hoop, one of the team’s balls must be knocked through the current hoop in the right direction. The first team to score 7 points wins. If the game reaches 6-6, a final deciding hoop is played. Note that a team cannot score more than 7 points – the game ends as soon as the 7 th hoop is won.
The balls are played in a fixed order: blue, red, black (blue’s partner) then yellow (red’s partner). We can record the progress of a match by recording the outcome of each shot. The code we are using is:
S a standard shot that does not make a hoop H a shot that makes a hoop for the team who played the shot D a shot that makes 2 hoops for the team who played the shot – an extremely unlikely scenario but it can happen! A team on 6 points will only score the first of the two hoops, of course.
O a shot that makes a hoop for an opponent’s ball!
The last one is almost certainly an accident, but it happens far more times than players like!
输入
The input represents part or all of a single game of golf croquet. The first two lines each contain the name of a team, each consisting of one or more words. The name will be no more than 30 characters long. The first named team play blue and black. The third line is a single integer, S, which tells how many strokes are recorded, for a game that has started but which may not yet be completed. (0 < S <= 255)
The fourth line contains S upper case letter characters, each being one of the 4 characters defined above (S, H, D or O). Blue always plays the first shot followed in turn by red, black and yellow.
输出
Output a single line of text with the current score in the form
team1name x team2name y.
Follow this by a space then one of:
teamname has won.
teamname is winning.
All square.
样例输入
Team Sally
The dragons
26
SSSSHSSSSSHSSSSSHSSSSSSHSS
样例输出
Team Sally 3 The dragons 1. Team Sally is winning.
这个题题面乱七八糟的,其实就是两个队伍,上4个队员,蓝、红、黑、黄,蓝和黑一队红和黄一队,一次打球,S是不中,H中了加一分,D中了加两分,O给对面加一分,按照这个顺序打,颜色啥用没有,但是读者不了解高尔夫规则,看了半天才发现没用。
题目简化为:
两个队伍打比赛,队伍1先打队伍2后打,存在4种情况,S不加分,H加一分,D加两分,O给对手加一分,分数不能高过7(如果已经6分,出现了D,那么也只加一分),给你两个队,给你一个数字表示过了多少回合。
- 如果有队伍到7分,那么游戏结束
- 在输出时,先输出两个队伍的分数
1.如果有队伍到了7分,那么输出该队伍赢了
2.如果没有队伍到达7分,那么输出分数高的队伍现在是赢的(is winning进行时)
3.如果平手,输出平手
这真的真的是个S13题,我们做的时候因为题面搞了好久,C
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
string a,b;
int n;
string s;
int main()
{
getline(cin,a);
getline(cin,b);
cin>>n;
cin>>s;
int ans1=0,ans2=0;
int len = s.length();//突然发现N都给了还求个锤子的LEN,我佛了
char ch;
for(int i=0;i<len;i++)
{
ch=s[i];
if(i%2==0)
{
if(ch=='S')continue;
else if(ch=='H')ans1++;
else if(ch=='D')ans1=ans1+2;
else ans2++;
}
else
{
if(ch=='S')continue;
else if(ch=='H')ans2++;
else if(ch=='D')ans2=ans2+2;
else ans1++;
}
if(ans1>=7||ans2>=7)
{
break;
}
}
if (ans1 > 7) ans1 = 7;
if (ans2 > 7) ans2 = 7;
cout<<a<<" "<<ans1<<" "<<b<<" "<<ans2<<". ";
if(ans1==ans2) cout<<"All square."<<endl;
else
{
if(ans1>ans2)cout<<a;
else cout<<b;
if(ans1==7||ans2==7)cout<<" has won."<<endl;
else cout<<" is winning."<<endl;
}
return 0;
}