-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ01023_ToanLopBa.java
55 lines (51 loc) · 1.7 KB
/
J01023_ToanLopBa.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
51
52
53
54
55
import java.util.*;
import java.io.*;
import java.math.*;
public class J01023_ToanLopBa {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
while (t-- > 0) {
String s = sc.nextLine();
char[] cs = s.toCharArray();
char x = cs[3];
if (x == '*' || x == '/') {
System.out.println("WRONG PROBLEM!");
} else {
System.out.println(ptit(s, x));
}
}
}
public static boolean check(String a, String b) {
int n = a.length();
for (int i = 0; i < n; i++) {
if (a.charAt(i) == '?') {
continue;
} else if (a.charAt(i) != b.charAt(i)) {
return false;
}
}
return true;
}
public static String ptit(String a, char x) {
for (int i = 10; i <= 99; i++) {
for (int j = 10; j <= 99; j++) {
int add = i + j, subtract = i - j;
if (add >= 10 && add <= 99) {
String s = String.valueOf(i) + " + " + String.valueOf(j) + " = " + String.valueOf(i + j);
if (check(a, s)) {
return s;
}
}
if (subtract >= 10 && subtract <= 99) {
String s = String.valueOf(i) + " - " + String.valueOf(j) + " = " + String.valueOf(i - j);
if (check(a, s)) {
return s;
}
}
}
}
return "WRONG PROBLEM!";
}
}