코드비교

Old VersionNew Version
1import java.util.*; 1import java.util.*; 
2public class Main { 2public class Main { 
3static Scanner keyboard = new Scanner(System.in); 3static Scanner sc = new Scanner(System.in);
4public static void main(String[] args) { 4public static void main(String[] args) { 
5int T = keyboard.nextInt(); 5int T = sc.nextInt();
6keyboard.nextLine(); 6sc.nextLine();
7for (int i = 0; i < T; i++) { 7for (int i = 0; i < T; i++) { 
8boolean check1 = true; 8boolean ch1 = true;
9boolean check2 = true; 9boolean ch2 = true;
10String x = keyboard.nextLine(); 10String x = sc.nextLine();
11String y = ""; 11String y = ""; 
12String[] input=new String[3]; 12String[] input=new String[3]; 
13for (int j=0;j<3;j++) { 13for (int j=0;j<3;j++) { 
  
15} 15} 
16for (int k = 0; k < input[0].length(); k++) { 16for (int k = 0; k < input[0].length(); k++) { 
17if (input[0].charAt(k) >= '0' && input[0].charAt(k) <= '9') { 17if (input[0].charAt(k) >= '0' && input[0].charAt(k) <= '9') { 
18check1 = true; 18ch1 = true;
19} 19} 
20else if (input[0].charAt(0)=='-') { 20else if (input[0].charAt(0)=='-') { 
21check1=true; 21ch1=true;
22} 22} 
23else { 23else { 
24check1 = false; 24ch1 = false;
25break; 25break; 
26} 26} 
27} 27} 
28if (check1) { 28if (ch1) {
29for (int k = 0; k < input[2].length(); k++) { 29for (int k = 0; k < input[2].length(); k++) { 
30if (input[2].charAt(k) >= '0' && input[2].charAt(k) <= '9') { 30if (input[2].charAt(k) >= '0' && input[2].charAt(k) <= '9') { 
31check1 = true; 31ch1 = true;
32} else if (input[2].charAt(0) == '-') { 32}
33check1 = true; 33else if (input[2].charAt(0) == '-') {
34} else { 34ch1 = true;
35check1 = false; 35}
   36else { ch1 = false;
36break; 37break; 
37} 38} 
38} 39} 
39} 40} 
40if (input[1].contains("+") || input[1].contains("-") || input[1].contains("*") || input[1].contains("/") || input[1].contains("%")) { 41if (input[1].contains("+") || input[1].contains("-") || input[1].contains("*") || input[1].contains("/") || input[1].contains("%")) { 
41check2=true; 41ch2=true;
42} 43} 
43else { 44else { 
44check2=false; 44ch2=false;
45} 46} 
46if (check1 && check2) { 46if (ch1 && ch2) {
47String result=x; 47String result=x; result+=" = ";
48result+=" = ";   
49if (input[1].equals("+")) { 49if (input[1].equals("+")) { 
50result+=Integer.parseInt(input[0])+Integer.parseInt(input[2]); 50result+=Integer.parseInt(input[0])+Integer.parseInt(input[2]); 
51} 51} 
52else if (input[1].equals("-")) { 52else if
   53(input[1].equals("-")) {
53result+=Integer.parseInt(input[0])-Integer.parseInt(input[2]); 54result+=Integer.parseInt(input[0])-Integer.parseInt(input[2]); 
54} 55} 
55else if (input[1].equals("*")) { 56else if (input[1].equals("*")) { 
  
58else if (input[1].equals("/")) { 59else if (input[1].equals("/")) { 
59if (input[2].equals("0")) { 60if (input[2].equals("0")) { 
60result="Wrong Input: 0"; 61result="Wrong Input: 0"; 
61//result+=input[0];   
62} 62} 
63else 63else 
64result+=Integer.parseInt(input[0])/Integer.parseInt(input[2]); 64result+=Integer.parseInt(input[0])/Integer.parseInt(input[2]); 
  
71else { 71else { 
72String result="Wrong Input: "; 72String result="Wrong Input: "; 
73boolean ww=true; 73boolean ww=true; 
74if (check2) { 74if (ch2) {
75for (int j = 0; j < input[0].length(); j++) { 75for (int j = 0; j < input[0].length(); j++) { 
76if (input[0].charAt(0)=='-' || (input[0].charAt(j) >= '0' && input[0].charAt(j) <= '9')) { 76if (input[0].charAt(0)=='-' || (input[0].charAt(j) >= '0' && input[0].charAt(j) <= '9')) { 
77ww = true; 77ww = true; 
78} 78} 
79else { 79else { ww=false; break; }
80ww=false;   
81break;   
82}   
83} 80} 
84if (ww) { 81if (ww) { 
85result += input[2]; 82result += input[2]; 
86} else { 83}
   84else {
87result += input[0]; 85result += input[0]; 
88} 86} 
89} 87} 
  
96} 94} 
97if (ww) { 95if (ww) { 
98result += input[1]; 96result += input[1]; 
99} else { 97}
   98else {
100result += input[0]; 99result += input[0]; 
101} 100} 
102} 101} 
import java.util.*;
public class Main {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
int T = keyboard.nextInt();
keyboard.nextLine();
for (int i = 0; i < T; i++) {
boolean check1 = true;
boolean check2 = true;
String x = keyboard.nextLine();
String y = "";
String[] input=new String[3];
for (int j=0;j<3;j++) {
input[j]=x.split(" ")[j];
}
for (int k = 0; k < input[0].length(); k++) {
if (input[0].charAt(k) >= '0' && input[0].charAt(k) <= '9') {
check1 = true;
}
else if (input[0].charAt(0)=='-') {
check1=true;
}
else {
check1 = false;
break;
}
}
if (check1) {
for (int k = 0; k < input[2].length(); k++) {
if (input[2].charAt(k) >= '0' && input[2].charAt(k) <= '9') {
check1 = true;
} else if (input[2].charAt(0) == '-') {
check1 = true;
} else {
check1 = false;
break;
}
}
}
if (input[1].contains("+") || input[1].contains("-") || input[1].contains("*") || input[1].contains("/") || input[1].contains("%")) {
check2=true;
}
else {
check2=false;
}
if (check1 && check2) {
String result=x;
result+=" = ";
if (input[1].equals("+")) {
result+=Integer.parseInt(input[0])+Integer.parseInt(input[2]);
}
else if (input[1].equals("-")) {
result+=Integer.parseInt(input[0])-Integer.parseInt(input[2]);
}
else if (input[1].equals("*")) {
result+=Integer.parseInt(input[0])*Integer.parseInt(input[2]);
}
else if (input[1].equals("/")) {
if (input[2].equals("0")) {
result="Wrong Input: 0";
//result+=input[0];
}
else
result+=Integer.parseInt(input[0])/Integer.parseInt(input[2]);
}
else {
result+=Integer.parseInt(input[0])%Integer.parseInt(input[2]);
}
System.out.println(result);
}
else {
String result="Wrong Input: ";
boolean ww=true;
if (check2) {
for (int j = 0; j < input[0].length(); j++) {
if (input[0].charAt(0)=='-' || (input[0].charAt(j) >= '0' && input[0].charAt(j) <= '9')) {
ww = true;
}
else {
ww=false;
break;
}
}
if (ww) {
result += input[2];
} else {
result += input[0];
}
}
else {
for (int j = 0; j < input[0].length(); j++) {
if (!(input[0].charAt(j) >= '0' && input[0].charAt(j) <= '9')) {
ww = false;
break;
}
}
if (ww) {
result += input[1];
} else {
result += input[0];
}
}
System.out.println(result);
}
}
}
}
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int T = sc.nextInt();
sc.nextLine();
for (int i = 0; i < T; i++) {
boolean ch1 = true;
boolean ch2 = true;
String x = sc.nextLine();
String y = "";
String[] input=new String[3];
for (int j=0;j<3;j++) {
input[j]=x.split(" ")[j];
}
for (int k = 0; k < input[0].length(); k++) {
if (input[0].charAt(k) >= '0' && input[0].charAt(k) <= '9') {
ch1 = true;
}
else if (input[0].charAt(0)=='-') {
ch1=true;
}
else {
ch1 = false;
break;
}
}
if (ch1) {
for (int k = 0; k < input[2].length(); k++) {
if (input[2].charAt(k) >= '0' && input[2].charAt(k) <= '9') {
ch1 = true;
}
else if (input[2].charAt(0) == '-') {
ch1 = true;
}
else { ch1 = false;
break;
}
}
}
if (input[1].contains("+") || input[1].contains("-") || input[1].contains("*") || input[1].contains("/") || input[1].contains("%")) {
ch2=true;
}
else {
ch2=false;
}
if (ch1 && ch2) {
String result=x; result+=" = ";
if (input[1].equals("+")) {
result+=Integer.parseInt(input[0])+Integer.parseInt(input[2]);
}
else if
(input[1].equals("-")) {
result+=Integer.parseInt(input[0])-Integer.parseInt(input[2]);
}
else if (input[1].equals("*")) {
result+=Integer.parseInt(input[0])*Integer.parseInt(input[2]);
}
else if (input[1].equals("/")) {
if (input[2].equals("0")) {
result="Wrong Input: 0";
}
else
result+=Integer.parseInt(input[0])/Integer.parseInt(input[2]);
}
else {
result+=Integer.parseInt(input[0])%Integer.parseInt(input[2]);
}
System.out.println(result);
}
else {
String result="Wrong Input: ";
boolean ww=true;
if (ch2) {
for (int j = 0; j < input[0].length(); j++) {
if (input[0].charAt(0)=='-' || (input[0].charAt(j) >= '0' && input[0].charAt(j) <= '9')) {
ww = true;
}
else { ww=false; break; }
}
if (ww) {
result += input[2];
}
else {
result += input[0];
}
}
else {
for (int j = 0; j < input[0].length(); j++) {
if (!(input[0].charAt(j) >= '0' && input[0].charAt(j) <= '9')) {
ww = false;
break;
}
}
if (ww) {
result += input[1];
}
else {
result += input[0];
}
}
System.out.println(result);
}
}
}
}