跳到主要內容

UVA489

Hangman Judge 

In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follows:
  1. The contestant tries to solve to puzzle by guessing one letter at a time.
  2. Every time a guess is correct, all the characters in the word that match the guess will be ``turned over.'' For example, if your guess is ``o'' and the word is ``book'', then both ``o''s in the solution will be counted as ``solved.''
  3. Every time a wrong guess is made, a stroke will be added to the drawing of a hangman, which needs 7 strokes to complete. Each unique wrong guess only counts against the contestant once.
       ______   
       |  |     
       |  O     
       | /|\    
       |  |     
       | / \    
     __|_       
     |   |______
     |_________|
  4. If the drawing of the hangman is completed before the contestant has successfully guessed all the characters of the word, the contestant loses.
  5. If the contestant has guessed all the characters of the word before the drawing is complete, the contestant wins the game.
  6. If the contestant does not guess enough letters to either win or lose, the contestant chickens out.
Your task as the ``Hangman Judge'' is to determine, for each game, whether the contestant wins, loses, or fails to finish a game.

Input

Your program will be given a series of inputs regarding the status of a game. All input will be in lower case. The first line of each section will contain a number to indicate which round of the game is being played; the next line will be the solution to the puzzle; the last line is a sequence of the guesses made by the contestant. A round number of -1 would indicate the end of all games (and input).

Output

The output of your program is to indicate which round of the game the contestant is currently playing as well as the result of the game. There are three possible results:

You win.
You lose.
You chickened out.

Sample Input


1
cheese
chese
2
cheese
abcdefg
3
cheese
abcdefgij
-1

Sample Output


Round 1
You win.
Round 2
You chickened out.
Round 3
You lose.





-------------------------------------------------------------------------------------------------------------

#include<stdio.h>
#include<string.h>
#define maxn 100
int left, chance;
char s[maxn], s2[maxn];
int win, lose;

void guess(char ch) {
  int bad = 1;
  for(int i = 0; i < strlen(s); i++)
    if(s[i] == ch) { left--; s[i] = ' '; bad = 0; }
  if(bad) --chance;
  if(!chance) lose = 1;
  if(!left) win = 1;
}

int main() {
  int rnd;
  while(scanf("%d%s%s", &rnd, s, s2) == 3 && rnd != -1) {
    printf("Round %d\n", rnd);
    win = lose = 0;
    left = strlen(s);
    chance = 7;
    for(int i = 0; i < strlen(s2); i++) {
      guess(s2[i]);
      if(win || lose) break;
    }
    if(win) printf("You win.\n");
    else if(lose) printf("You lose.\n");
    else printf("You chickened out.\n");
  }
  return 0;
}

留言

這個網誌中的熱門文章

UVA11349

J - Symmetric Matrix Time Limit: 1 sec Memory Limit: 16MB You`re given a square matrix M. Elements of this matrix are M ij : {0 < i < n, 0 < j < n}. In this problem you'll have to find out whether the given matrix is symmetric or not. Definition: Symmetric matrix is such a matrix that all elements of it are non-negative and symmetric with relation to the center of this matrix. Any other matrix is considered to be non-symmetric. For example: All you have to do is to find whether the matrix is symmetric or not. Elements of a matrix given in the input are -2 32  <= M ij  <= 2 32  and 0 < n <= 100. INPUT: First line of input contains number of test cases T <= 300. Then T test cases follow each described in the following way. The first line of each test case contains n - the dimension of square matrix. Then n lines follow each of then containing row i. Row contains exactly n elements separated by a space character. j-th number in row i is the elem

UVA11461

A square number is an integer number whose square root is also an integer. For example 1, 4, 81 are some square numbers. Given two numbers a and b you will have to find out how many square numbers are there between a and b (inclusive). Input The input file contains at most 201 lines of inputs. Each line contains two integers a and b (0 < a ≤ b ≤ 100000). Input is terminated by a line containing two zeroes. This line should not be processed. Output For each line of input produce one line of output. This line contains an integer which denotes how many square numbers are there between a and b (inclusive). Sample Input 1 4 1 10 0 0 Sample Output 2 3 大意:給兩個數字 求範圍內平方不大於第二個數字的數量 解法: 以最大數取根號後往回看 import java.util.Scanner; public class UVA11461 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int start = sc.nextInt(); int last = sc.nextInt(); if (last == 0) break; System.o

UVA11005

Problem B Cheapest Base Input:  Standard Input Output:  Standard Output When printing text on paper we need ink. But not every character needs the same amount of ink to print: letters such as 'W', 'M' and '8' are more expensive than thinner letters as ' i ', 'c' and '1'. In this problem we will evaluate the cost of printing numbers in several bases. As you know, numbers can be expressed in several different bases. Well known bases are binary (base 2; digits 0 and 1), decimal (base 10; digits 0 to 9) and hexadecimal (base 16; digits 0 to 9 and letters A to F). For the general base  n  we will use the first  n  characters of the string "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", which means the highest base in this problem is 36. The lowest base is of course 2. Every character from this string has an associated cost, represented by an integer value between 1 and 128. The cost to print a number in a certain base is the s