코드비교

Old VersionNew Version
1import java.util.*; 1import java.util.Scanner;
2public class Main { 2public class Main { 
3public static void main(String[] args) { 3public static void main(String[] args) { 
4Scanner sc=new Scanner(System.in); 4Scanner scn = new Scanner(System.in);
5int n=sc.nextInt(); 5int num = scn.nextInt();
6sc.nextLine(); 6scn.nextLine();//string입력받기 전에 개행문자 없애주기
7StringBuffer arr[]=new StringBuffer[n]; 7String[] ans = new String[num];
8for(int i=0;i<n;i++) { 8for (int i = 0; i < num; i++) {
9String a=sc.nextLine(); 9ans[i] = scn.nextLine().toLowerCase();
10a=a.toLowerCase(); 10}
11arr[i]=new StringBuffer(a); 11//자바에서 문자열은 immutable이라 바꿀 수 없음...
12for(int j=0;j<arr[i].length();j++) { 12for (int i=0;i<num;i++) {
13switch (arr[i].charAt(j)) { 13for(int j=0;j<ans[i].length();j++) {
14case 'a': 14if(97 <= ans[i].charAt(j) && ans[i].charAt(j) <= 122) {
15case 'b': 15switch(ans[i].charAt(j)) {
16case 'c': 16case 'a': case'b': case'c':
17arr[i].setCharAt(j,'2'); 17ans[i] = ans[i].substring(0,j) + "2" + ans[i].substring(j+1);
18break; 18break; 
19case 'd': 19case 'd': case'e': case'f':
20case 'e': 20ans[i] = ans[i].substring(0,j) + "3" + ans[i].substring(j+1);
21case 'f':   
22arr[i].setCharAt(j,'3');   
23break; 21break; 
24case 'g': 24case 'g': case'h': case'i':
25case 'h': 25ans[i] = ans[i].substring(0,j) + "4" + ans[i].substring(j+1);
26case 'i':   
27arr[i].setCharAt(j,'4');   
28break; 24break; 
29case 'j': 29case 'j': case'k': case'l':
30case 'k': 30ans[i] = ans[i].substring(0,j) + "5" + ans[i].substring(j+1);
31case 'l':   
32arr[i].setCharAt(j,'5');   
33break; 27break; 
34case 'm': 34case 'm': case'n': case'o':
35case 'n': 35ans[i] = ans[i].substring(0,j) + "6" + ans[i].substring(j+1);
36case 'o':   
37arr[i].setCharAt(j,'6');   
38break; 30break; 
39case 'p': 39case 'p': case'q': case'r': case's':
40case 'q': 40ans[i] = ans[i].substring(0,j) + "7" + ans[i].substring(j+1);
41case 'r':   
42case 's':   
43arr[i].setCharAt(j,'7');   
44break; 33break; 
45case 't': 45case 't': case'u': case'v':
46case 'u': 46ans[i] = ans[i].substring(0,j) + "8" + ans[i].substring(j+1);
47case 'v':   
48arr[i].setCharAt(j,'8');   
49break; 36break; 
50case 'w': 50case 'w': case'x': case'y': case'z':
51case 'x': 51ans[i] = ans[i].substring(0,j) + "9" + ans[i].substring(j+1);
52case 'y':   
53case 'z':   
54arr[i].setCharAt(j,'9');   
55break; 39break; 
56} 40} 
57} 41} 
58} 42} 
59for(int i=0;i<n;i++) 59System.out.println(ans[i]);
60System.out.println(arr[i]);   
61} 44} 
62} 45} 
  46} 
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
StringBuffer arr[]=new StringBuffer[n];
for(int i=0;i<n;i++) {
String a=sc.nextLine();
a=a.toLowerCase();
arr[i]=new StringBuffer(a);
for(int j=0;j<arr[i].length();j++) {
switch (arr[i].charAt(j)) {
case 'a':
case 'b':
case 'c':
arr[i].setCharAt(j,'2');
break;
case 'd':
case 'e':
case 'f':
arr[i].setCharAt(j,'3');
break;
case 'g':
case 'h':
case 'i':
arr[i].setCharAt(j,'4');
break;
case 'j':
case 'k':
case 'l':
arr[i].setCharAt(j,'5');
break;
case 'm':
case 'n':
case 'o':
arr[i].setCharAt(j,'6');
break;
case 'p':
case 'q':
case 'r':
case 's':
arr[i].setCharAt(j,'7');
break;
case 't':
case 'u':
case 'v':
arr[i].setCharAt(j,'8');
break;
case 'w':
case 'x':
case 'y':
case 'z':
arr[i].setCharAt(j,'9');
break;
}
}
}
for(int i=0;i<n;i++)
System.out.println(arr[i]);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int num = scn.nextInt();
scn.nextLine();//string입력받기 전에 개행문자 없애주기
String[] ans = new String[num];
for (int i = 0; i < num; i++) {
ans[i] = scn.nextLine().toLowerCase();
}
//자바에서 문자열은 immutable이라 바꿀 수 없음...
for (int i=0;i<num;i++) {
for(int j=0;j<ans[i].length();j++) {
if(97 <= ans[i].charAt(j) && ans[i].charAt(j) <= 122) {
switch(ans[i].charAt(j)) {
case 'a': case'b': case'c':
ans[i] = ans[i].substring(0,j) + "2" + ans[i].substring(j+1);
break;
case 'd': case'e': case'f':
ans[i] = ans[i].substring(0,j) + "3" + ans[i].substring(j+1);
break;
case 'g': case'h': case'i':
ans[i] = ans[i].substring(0,j) + "4" + ans[i].substring(j+1);
break;
case 'j': case'k': case'l':
ans[i] = ans[i].substring(0,j) + "5" + ans[i].substring(j+1);
break;
case 'm': case'n': case'o':
ans[i] = ans[i].substring(0,j) + "6" + ans[i].substring(j+1);
break;
case 'p': case'q': case'r': case's':
ans[i] = ans[i].substring(0,j) + "7" + ans[i].substring(j+1);
break;
case 't': case'u': case'v':
ans[i] = ans[i].substring(0,j) + "8" + ans[i].substring(j+1);
break;
case 'w': case'x': case'y': case'z':
ans[i] = ans[i].substring(0,j) + "9" + ans[i].substring(j+1);
break;
}
}
}
System.out.println(ans[i]);
}
}
}