-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12289.java
50 lines (35 loc) · 933 Bytes
/
12289.java
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
/*
* UVa 12289: One-Two-Three
*
* Problem Statement: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3710
*/
import java.util.Scanner;
public class Main {
public static boolean isClose(String target, String attempt) {
if (target.length() != attempt.length())
return false;
int error = 0;
for (int i = 0; i < target.length(); i++) {
if (target.charAt(i) != attempt.charAt(i))
error++;
if (error > 1)
return false;
}
return true;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String inp;
for (int i = 0; i < n; i++) {
inp = scan.next();
if (isClose("one", inp))
System.out.println("1");
else if (isClose("two", inp))
System.out.println("2");
else if (isClose("three", inp))
System.out.println("3");
}
scan.close();
}
}