UVa 489 Hangman Judge [模拟]

来源:互联网 发布:手机淘宝怎样添加客服 编辑:程序博客网 时间:2024/04/30 16:30

Description

给两个字符串
第二个字符串是用来猜第一个字符串
如果猜对了
那么该字符串的全部该字母就显示出来
否则就计数器++
如果计数器达到了7,就GG了
问是否GG
同时还有放弃的情况

Hint

直接cin.nextInt之后nextLine不行
不知为何。。。

Code

import java.util.Scanner;public class Main {  public static void main(String[] args) {    Scanner cin = new Scanner(System.in);    for (;;) {      String r = cin.nextLine();      if (r.equals("-1")) break;      System.out.println("Round " + r);      char[] ans = cin.nextLine().toCharArray();      boolean[] b = new boolean[26];      int size = 0;      for (char x : ans) {        if (!b[x - 'a']) size++;        b[x - 'a'] = true;      }      boolean[] c = b.clone();      char[] s = cin.nextLine().toCharArray();      int total = 0;      for (char x : s) {        if (size == 0) break;        if (!b[x - 'a'] && !c[x - 'a']) {          total++;          continue;        }        if (b[x - 'a'] &&  !c[x - 'a']) {          total++;          continue;        }        c[x - 'a'] = false;        size--;      }      if (total >= 7) {        System.out.println("You lose.");      }else {        if (size == 0)          System.out.println("You win.");        else          System.out.println("You chickened out.");      }    }  }}
0 0
原创粉丝点击