2013-06-26 14:53:38Morris

[UVA] 584 - Bowling


  Bowling 

History 

Bowling has been traced to articles found in the tomb of an Egyptian child buried in 5200 BC. The primitive implements included nine pieces of stone at which a stone ``ball'' was rolled, the ball having first to roll through an archway made of three pieces of marble.

Another ancient discovery was the Polynesian game of ula maika, which also used pins and balls of stone. The stones were to be rolled at targets 60 feet away, a distance which is still one of the basic regulations of tenpins.

Bowling at tenpins probably originated in Germany, not as a sport but as a religious ceremony. Martin Luther is credited with settling on nine as the ideal number of pins.

Tracing history reveals the game moved through Europe, the Scandinavian countries and finally to the United States, where the earliest known reference to bowling at pins in America was made by author Washington Irving about 1818 in Rip Van Winkle.

Although the game was being played throughout the world, rules were different almost everywhere, and even basic equipment was not the same. In fact, why and when the 10th pin was added from the European game of ninepins to the American game of tenpins is still a mystery.

Rules 

A single bowling game consists of ten frames. The object in each frame is to roll a ball at ten bowling pins arranged in an equilateral triangle and to knock down as many pins as possible.

For each frame, a bowler is allowed a maximum of two rolls to knock down all ten pins. If the bowler knocks them all down on the first attempt, the frame is scored as a strike. If the bowler does not knock them down on the first attempt in the frame the bowler is allowed a second attempt to knock down the remaining pins. If the bowler succeeds in knocking the rest of the pins down in the second attempt, the frame is scored as a spare.


The score for a bowling game consists of sum of the scores for each frame. The score for each frame is the total number of pins knocked down in the frame, plus bonuses for strikes and spares. In particular, if a bowler scores a strike in a particular frame, the score for that frame is ten plus the sum of the next two rolls. If a bowler scores a spare in a particular frame, the score for that frame is ten plus the score of the next roll. If a bowler scores a strike in the tenth (final) frame, the bowler is allowed two more rolls. Similarly, a bowler scoring a spare in the tenth frame is allowed one more roll.

The maximum possible score in a game of bowling (strikes in all ten frames plus two extra strikes for the tenth frame strike) is 300.

Input 

The input will consist of a sequence of bowling game scores. Each line will contain the scores for a single game, with the scores for each roll of the ball separated by a single space. The score for a single roll will be represented by a single character -- either a number indicating the number of pins knocked down, a '/' for a spare or a 'X' for a strike.

The end of input is indicated by a single line containing the text Game Over (terminated with a newline).

Output 

Your program should output the total game score for each game in the input file. The game scores should be left justified and each score should be printed on a separate line. The order of the scores on the output should correspond to the order of the games on the input.

Sample Input 

1 0 1 / 2 2 X 3 3 X 1 / 3 / X 1 2
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / X 8 0
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / 8 / 9
Game Over

Sample Output 

108
121
120



Miguel A. Revilla
1998-03-10

保齡球的規則是 10 局
每局最多丟兩次, 第一次沒全倒則丟第二次。
然而如果發生第一次 X 則這局得分會加上下兩次倒瓶數
反之如果產生第二次時全倒, 則加上下一次倒瓶數

#include <stdio.h>
#include <sstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    string line;
    while(getline(cin, line)) {
        if(line == "Game Over")
            break;
        stringstream sin(line);
        vector<pair<int, int> > frame;
        int n = 0, i;
        for(i = 0; i < line.length(); i++) {
            if(line[i] != ' ') {
                line[n++] = line[i];
            }
        }
        int score = 0;
        for(i = 0; i < n; i++) {
            if(line[i] == 'X') {
                frame.push_back(make_pair(10, 0));
            } else {
                if(line[i+1] == '/')
                    frame.push_back(make_pair(line[i]-'0', 10-(line[i]-'0')));
                else
                    frame.push_back(make_pair(line[i]-'0', line[i+1]-'0'));
                i++;
            }
        }
        for(i = 0; i < 10; i++) {
            if(frame[i].first + frame[i].second != 10)
                score += frame[i].first + frame[i].second;
            else if(frame[i].first == 10) {
                if(frame[i+1].first == 10)
                    score += 10 + 10 + frame[i+2].first;
                else
                    score += 10 + frame[i+1].first + frame[i+1].second;
            } else {
                score += 10 + frame[i+1].first;
            }
        }
        printf("%d\n", score);
    }
    return 0;
}

sesso videos 2018-06-09 23:22:48

Thank you..

sexe videos 2018-06-09 23:22:09

Thank you..