1.


/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* Problem: 489 Hangman Judge
* Link:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=430
*
* @author Rolf Schirm
* @version 1.0, 03/23/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.932
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {
public static void main(String... args) throws Exception {
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));

while(true) {
int round = Integer.parseInt(scan.readLine());

if(round == -1) {
break;
}

String solution = scan.readLine();
String guesses = scan.readLine();

Set<Character> set = new HashSet<Character>();

int fails = 0;

for(int i = 0; i < solution.length() && set.size() <= 26; i++) {
set.add(solution.charAt(i));
}

for(int i = 0; i < guesses.length() && fails < 7; i++) {
char c = guesses.charAt(i);
if(!set.remove(c)) {
fails++;
} else if(set.isEmpty()) {
break;
}
}

System.out.println("Round " + round);

if(set.isEmpty()) {
System.out.println("You win.");
} else if(fails < 7) {
System.out.println("You chickened out.");
} else {
System.out.println("You lose.");
}
}
}
}


2.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* Problem: 489 - Hangman Judge
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=430
*
* @author Christian Posselt
* @author Christian Mitterreiter
* @version 1.0, 23.03.2011
*
* Status: Accepted
* Time: 2.108
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.TreeSet;

public class Main {


public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

//Set of distinct characters that form the solution
Set<Character> charsInSolution;

//Set of distinct characters that were asked by the user
Set<Character> askedChars;

int round;
int wrongGuess;

do
{
wrongGuess = 0;
round = Integer.parseInt(reader.readLine());

//exit if round = -1
if(round == -1)
break;

charsInSolution = new TreeSet<Character>();
askedChars = new TreeSet<Character>();

//insert characters into solution set
for(char c: reader.readLine().toCharArray())
if(!charsInSolution.contains(c))
charsInSolution.add(c);

for(char c: reader.readLine().toCharArray())
{
//if word was guessed or hangman is completed, stop testing
if(charsInSolution.isEmpty() || wrongGuess == 7)
break;

//if character was already asked, ignore
if(askedChars.contains(c))
continue;

askedChars.add(c);

//check whether the char given by user is part of the solution or not
if(charsInSolution.contains(c))
charsInSolution.remove(c);
else
wrongGuess++;
}

System.out.println("Round " + round);

//solution guessed
if(charsInSolution.isEmpty())
System.out.println("You win.");
//hangman not completed, but solution not found yet
else if(!charsInSolution.isEmpty() && wrongGuess < 7)
System.out.println("You chickened out.");
//lost the game
else
System.out.println("You lose.");

}
while(reader.ready());


}

}


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



1.

import java.util.*;
import java.io.*;

class Main {

public static void main(String...args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input;
int round, fail, guess;
Set<Character> set = new HashSet<Character>();
Set<Character> guesses = new HashSet<Character>();

while( (input = reader.readLine()) != null)
{
guess = 0;
fail = 0;
set.clear();
guesses.clear();

round = Integer.parseInt(input);
if(round == -1)
break;

input = reader.readLine();

for(int i = 0; i < input.length(); i++)
set.add(input.charAt(i));

input = reader.readLine();
for(int i = 0; i < input.length(); i++)
{
if(!guesses.contains(input.charAt(i)))
if(set.contains(input.charAt(i)))
{
guess++;
if(guess >= set.size())
break;
}
else
{
fail++;
if(fail >= 7)
break;
}

guesses.add(input.charAt(i));
}

System.out.println("Round " + round);


if(guess >= set.size())
System.out.println("You win.");
else
if(fail >= 7)
System.out.println("You lose.");
else
System.out.println("You chickened out.");

}
}
}

2.

/**
* FWP: Ausgewaehlte Probleme aus dem ACM (SS10)
*
* Method: ad hoc
* Problem: 489 - Hangman Judge
* Accepted: 2.036
* @author Evgeni Pavlidis
*
*/
import java.util.*;
import java.io.*;

class Main {

public static void main(String...args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input;
int round, fail, guess;
Set<Character> set = new HashSet<Character>();
Set<Character> guesses = new HashSet<Character>();

while( (input = reader.readLine()) != null)
{
guess = 0;
fail = 0;
set.clear();
guesses.clear();

round = Integer.parseInt(input);
if(round == -1)
break;

input = reader.readLine();

for(int i = 0; i < input.length(); i++)
set.add(input.charAt(i));

input = reader.readLine();
for(int i = 0; i < input.length(); i++)
{
if(!guesses.contains(input.charAt(i)))
if(set.contains(input.charAt(i)))
{
guess++;
if(guess >= set.size())
break;
}
else
{
fail++;
if(fail >= 7)
break;
}

guesses.add(input.charAt(i));
}

System.out.println("Round " + round);


if(guess >= set.size())
System.out.println("You win.");
else
if(fail >= 7)
System.out.println("You lose.");
else
System.out.println("You chickened out.");

}
}
}