Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.util.HashMap;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- while(sc.hasNext()) {
- int rounds = Integer.parseInt(sc.nextLine());
- if(rounds != -1) {
- HashMap<Character, Boolean> solution = new HashMap<>();
- String thisSolution = sc.nextLine();
- for(int i = 0; i < thisSolution.length(); i++) {
- solution.put(thisSolution.charAt(i), false);
- }
- String thisGuess = sc.nextLine();
- ArrayList<Character> guesses = new ArrayList<>();
- for(int i = 0; i < thisGuess.length(); i++) {
- guesses.add(thisGuess.charAt(i));
- }
- System.out.println("Round " + rounds);
- System.out.println(gameResult(solution, guesses));
- }
- }
- }
- static String gameResult(HashMap<Character, Boolean> gameQ, ArrayList<Character> guess) {
- ArrayList<Character> guessedCorrectChar = new ArrayList<>();
- ArrayList<Character> guessedWrongChar = new ArrayList<>();
- for(int i = 0; i < guess.size(); i++) {
- if(!guessedCorrectChar.contains(guess.get(i)) || !guessedWrongChar.contains(guess.get(i))) {
- for(Character k : gameQ.keySet()) {
- if(guess.get(i) == k) {
- gameQ.replace(k, true);
- if(!guessedCorrectChar.contains(k)) {
- guessedCorrectChar.add(k);
- }
- }
- }
- if(!guessedCorrectChar.contains(guess.get(i)) && !guessedWrongChar.contains(guess.get(i))) {
- guessedWrongChar.add(guess.get(i));
- }
- }
- if(!gameQ.containsValue(false) && guessedWrongChar.size() < 7) {
- return "You win.";
- }
- }
- if(guessedWrongChar.size() >= 7) {
- return "You lose.";
- }
- return "You chickened out.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement