zoukankan      html  css  js  c++  java
  • uva 489.Hangman Judge 解题报告

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=430

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 using namespace std;
     6 
     7 const int maxn = 100;
     8 
     9 int l, chance;
    10 char s[maxn], s2[maxn];
    11 int win, lose;
    12 
    13 void guess(char ch)
    14 {
    15     int bad = 1;
    16     for (int i = 0; i < strlen(s); i++) {
    17         if (s[i] == ch) {
    18             l--;
    19             s[i] = '#';
    20             bad = 0;
    21         }
    22     }
    23     if (bad) --chance;
    24     if (!chance) lose = 1;
    25     if (!l) win = 1;
    26 }
    27 
    28 int main()
    29 {
    30     int rnd;
    31     #ifndef ONLINE_JUDGE
    32         freopen("in.txt", "r", stdin);
    33     #endif // ONLINE_JUDGE
    34     while (scanf("%d%s%s", &rnd, s, s2) == 3 && rnd != -1) {
    35         printf("Round %d
    ", rnd);
    36         win = lose = 0;
    37         l = strlen(s);
    38         chance = 7;
    39         for (int i = 0; i < strlen(s2); i++) {
    40             guess(s2[i]);
    41             if (win || lose) break;
    42         }
    43 
    44         if (win) printf("You win.
    ");
    45         else if (lose) printf("You lose.
    ");
    46         else printf("You chickened out.
    ");
    47     }
    48     return 0;
    49 }
  • 相关阅读:
    poj 2674 Linear world
    poj 3185 The Water Bowls
    The Largest Clique (uva11324)
    Proving Equivalences (LA 4287)
    强联通分量( HihoCoder 1185 )
    求点双联通分量(HihoCoder
    求桥,割点(HihoCoder
    欧拉回路
    uva10054
    表达式树(公共表达式消除 uva 12219)
  • 原文地址:https://www.cnblogs.com/windysai/p/4846654.html
Copyright © 2011-2022 走看看