sicily 1100. Tennis Anyone?

1100. Tennis Anyone?

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

When there's a big tennis tournament going on, many airline passengers want to know the latest news as soon as they get off their flights. Flight Information Television (FIT) has a group of in-airport televisions to display latest sports results, including tennis and want your help to display the results of tennis matches.

Each tennis match is divided into sets. Each set is divided into games. Each game is divided into points. Your task is to write a program that produces the score for each set and the name of the winner of a match, if there is one.

The rules of the game are as follows:

  1. Alternating Servers
    At the beginning of the first game, one player shall be called the Server, and the other the Receiver. At the end of the first game the Receiver shall become Server, and the Server Receiver; and so on alternately in all the subsequent games. The Server’s score is always listed first in a score pair.
  2. Score in a Game
    If a player wins her first point, the score is called 15 for that player; on winning her
    second point, the score is called 30 for that player; on winning her third point, the score is called 40 for that player, and the fourth point won by a player is called “game” for that player except as below:
    If both players have won three points, the score is 40/40 which is called “deuce”. If the Server wins the next point, she has a scored the “advantage” and the score is given as “advantage-in” or “ad-in” for short. However, if the Receiver wins at “deuce” the advantage is given to the Receiver and score is called “advantage-out” or “ad-out” for short. If the same player wins the next point, she wins the game; if the other player wins the next point the score returns to “deuce”; and so on, until a player wins the two points immediately following the score of “deuce”.
  3. Score in a Set
    A player who first wins six games wins a set; except that she must win by a margin of two games over her opponent and if necessary a set is extended until this margin is achieved.
  4. Maximum Number of Sets
    The maximum number of sets in a match shall be 3. The winner of the match is the person that wins 2 sets.

Immediately after each point, the score of the game is called and the information about the games is sent to FIT.

Input

The input file will consist of one or more data sets, each representing a match. The first line of each data set contains the names of the players. There will be two strings of 1 to 80 letters, separated by at least one space. The first name on the line will be the Server for the first game. The next one or more lines of the data set contain the scores called out during a single game. One line will hold all the scores called during one game. These scores will either be a pair of numbers separated by white space (such as "0 0" or "40 15") or one of the words "ad-in", "ad-out", "deuce", or "game". All words in the score will be in lower case. No score will be given after a player has won, so each line will be terminated with the word "game". There will be at least one space between all scores on the score lines. The score lines for a game will end with a single line with the word "done". Each score line will represent a completed game, but the match, or even the set, may not be completed.
A line with the single word "quit" instead of the pair of names indicates the end of the input data.
You may assume all score lines represent valid games and there are never more score lines than are necessary for a match.

Output

The output for each match will consist of three lines. The first line will have the names of the two players in the same case and order listed in the input, separated by a single hyphen. The next line will have the number of games won by each player in each set separated by white space. For each set, have the games won by the first player listed first, a single hyphen, then the games won by the second player. Sets with a score of 0-0 should not be listed. The third line will either have the name of the player who won followed by the word "won" or the words "Match in progress" for a match that is not yet complete.
Print a blank line after the output for each data set.

Sample Input

ann mary
0 0 0 15 15 15 30 15 40 15 40 30 game
0 0 15 0 15 15 30 15 30 30 30 40 game
0 0 15 0 15 15 30 15 30 30 30 40 game
0 0 15 0 15 15 30 15 40 15 game
0 0 15 0 30 0 40 0 game
0 0 15 0 30 0 40 0 game
0 0 15 0 15 15 30 15 40 15 game
0 0 15 0 30 0 40 0 game
0 0 0 15 0 30 0 40 game
0 0 15 0 30 0 40 0 game
0 0 0 15 0 30 0 40 game
0 0 15 0 15 15 15 30 30 30 40 30 deuce ad-in game
0 0 15 0 30 0 40 0 game
done
Sara Nina
0 0 0 15 15 15 30 15 40 15 40 30 game
0 0 15 0 15 15 30 15 30 30 30 40 game
0 0 15 0 15 15 15 30 30 30 40 30 deuce ad-in deuce ad-in game
0 0 15 0 30 0 30 15 30 30 40 30 deuce ad-out game
0 0 0 15 0 30 15 30 15 40 30 40 deuce ad-out deuce ad-in game
0 0 15 0 15 15 30 15 30 30 30 40 game
0 0 15 0 15 15 30 15 40 15 game
0 0 15 0 30 0 40 0 game
0 0 15 0 30 0 40 0 game
0 0 15 0 15 15 30 15 40 15 game
0 0 15 0 30 0 40 0 game
0 0 0 15 0 30 0 40 game
0 0 15 0 30 0 40 0 game
0 0 0 15 0 30 0 40 game
done
quit

Sample Output

ann-mary
4-6 1-2
Match in progress

Sara-Nina
6-0 6-2
Sara won

题目分析

根据数据显示当前的网球得分

积分规则如下:

一,每场比赛3盘两胜

二,每盘比赛若某方赢6局且多胜对方2局则胜出,

否则加局至有一方多胜两局为止

三,每局得分为0, 15, 30, 40,

某方在得分40,对方少于30的情况下再赢一球则胜出

双方都是40,称为deuce,

此时server得分为ad-in,再得一球胜出

若是receiver得分为ad-out,再得一球胜出

若被对方得分则回到deuce状态

四,结束一局交换身份

熟悉以上规则后发现

其实不必要记录每局比赛的所有数据,只要参考game前的那个数据就可以知道该局比赛的server是否胜利

如0,15,30,ad-in为server胜利,40,ad-out为receiver胜利

判断赢了一盘是,得分超过6分且多于对手两分

最后只要有人赢了两盘即为胜出,否则为比赛中

一直WA,最后读题目中的input才知道数据间隔为不定数目的空格,

直接用getline函数还的去扫,

所以直接用std::cin来输入,保存倒数第二个输入进行判断


#include <iostream>
#include <cstdio>
#include <cstring>

std::string pattern[8] = {"0", "15", "30", "ad-in", "40", "ad-out"};

int check(std::string str) {
  for (int i = 0; i < 6; ++i)
    if (pattern[i] == str)
      return i;
}

int main()
{
  int score[3][2];
  std::string ap, bp;
  std::string str;
  while (std::cin >> ap) {
    if (ap == "quit")
      break;
    std::cin >> bp;

    memset(score, 0, sizeof(score));
    int count = 0;
    int server = 0;
    int point;
    std::string temp;
    while (std::cin >> str) {
      if (str == "done")
        break;
      while (std::cin >> str) {
        if (str == "game")
          break;
        temp = str;
      }
      point = check(temp);
//std::cout << point << std::endl;
      if (point <= 3) {
        score[count][server]++;
      } else {
        score[count][(server+1)%2]++;
      }

//std::cout << score[count][0] << "--" << score[count][1] << std::endl;
      if ( (score[count][0]>=6&&score[count][0]-score[count][1]>=2) ||
           (score[count][1]>=6&&score[count][1]-score[count][0]>=2) ) {
        count++;
      }
      server = (server+1)%2;
    }
    std::cout << ap << "-" << bp << std::endl;
    for (int i = 0; i < 3; ++i) {
      if (score[i][0] == 0 && score[i][1] == 0)
        break;
      if (i == 0) std::cout << score[i][0] << "-" << score[i][1];
      else std::cout << " " << score[i][0] << "-" << score[i][1];
    }
    std::cout << std::endl;
    int as = 0, bs = 0;
    for (int i = 0; i < count; ++i)
      if (score[i][0] > score[i][1])
        as++;
      else
        bs++;
    if (as == 2) std::cout << ap << " won" << std::endl;
    else if (bs == 2) std::cout << bp << " won" << std::endl;
    else std::cout << "Match in progress" << std::endl;
    std::cout << std::endl;
  }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值