코드비교

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