-
Notifications
You must be signed in to change notification settings - Fork 6
/
hangman.txt
116 lines (109 loc) · 3.52 KB
/
hangman.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.util.*;
import java.io.*;
import java.math.*;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
String word = in.nextLine();
String chars = in.nextLine();
String[] charater = chars.split(" ");
System.err.println(charater.length);
char[] resultat = new char[word.length()];
for(int i = 0 ;i< word.length();i++ ){
resultat[i]='_';
}
int error = 0;
String wordLower = word.toLowerCase();
System.err.println("word "+word);
System.err.println("chars "+chars);
String solu="";
if(wordLower.contains(" ")){
int pos1 = 0;
int tour = 0;
do{
if(tour == 0){
pos1= wordLower.indexOf(" ");
tour++;
}else{
pos1= wordLower.indexOf(" ",pos1+1);
}
if(pos1 != -1){
resultat[pos1]=' ';
}
}while(pos1 != -1);
}
for(String mot : charater){
if(wordLower.contains(mot) && !solu.contains(mot)){
int pos1 = 0;
int tour = 0;
do{
if(tour == 0){
pos1= wordLower.indexOf(mot);
tour++;
}else{
pos1= wordLower.indexOf(mot,pos1+1);
}
if(pos1 != -1){
resultat[pos1] = word.charAt(pos1);
}
}while(pos1 != -1);
}else{
error++;
}
solu += mot;
if(error>6) break;
}
result(error);
System.out.println(resultat);
}
public static void result(int error){
System.out.println("+--+");
StringBuilder builder0 = new StringBuilder();
StringBuilder builder1 = new StringBuilder();
StringBuilder builder2 = new StringBuilder();
builder0.append("|");
builder1.append("|");
builder2.append("|\\");
switch(error){
case 1 :
builder0.append(" o");
break;
case 2 :
builder0.append(" o");
builder1.append(" |");
break;
case 3 :
builder0.append(" o");
builder1.append(" /|");
break;
case 4 :
builder0.append(" o");
builder1.append(" /|");
builder1.append('\\');
break;
case 5 :
builder0.append(" o");
builder1.append(" /|");
builder1.append('\\');
builder2.append('/');
break;
case 6 :
builder0.append(" o");
builder1.append(" /|");
builder1.append('\\');
builder2.append('/');
builder2.append(' ');
builder2.append('\\');
break;
default:
break;
}
System.out.println(builder0.toString());
System.out.println(builder1.toString());
System.out.println(builder2.toString());
}
}