B - 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.

题意:
两人交替打高尔夫,以一串字符串给出,S代表击球过程,H代表打进球为自己得分,O表示给对方加分,D表示加两分,先得7分者获胜。

题解:
模拟
注意输出(is winning 和 has won)
has won:在字符串全部模拟之前就已经分出胜负

代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

char s1[265], s2[265];
int len;
char str[1005];

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    gets(s1), gets(s2);
    scanf("%d %s", &len, str);
    int sc1 = 0, sc2 = 0, i;
    for (i = 0; i < len; i++){
        if(str[i] == 'S') continue;
        if(str[i] == 'H'){
            if(i & 1) sc2++;
            else sc1++;
            if(sc2 == 7 || sc1 == 7) break;
        }else if(str[i] == 'O'){
            if(i & 1) sc1++;
            else sc2++;
            if(sc2 == 7 || sc1 == 7) break;
        }else{
            if(i & 1){
                sc2 += 2;
                if(sc2 >= 7) sc2 = 7;
                if(sc2 == 7) break;
            }else{
                sc1 += 2;
                if(sc1 >= 7) sc1 = 7;
                if(sc1 == 7) break;
            }
        }
    }
    printf("%s %d %s %d.", s1, sc1, s2, sc2);
    if(i >= len){
        if(sc1 > sc2) printf(" %s is winning.\n", s1);
        else if(sc1 < sc2) printf(" %s is winning.\n", s2);
        else printf(" All square.\n");
    }else{
        if(sc1 > sc2) printf(" %s has won.\n", s1);
        else if(sc1 < sc2) printf(" %s has won.\n", s2);
        else printf(" All square.\n");
    }


    return 0;
}
点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注