문자를 아스키코드 값으로 하나하나 나눠준후 값들을 반전시켜 비교한다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args){ | |
int[] a1 = new int[100]; | |
int[] b1 = new int[100]; | |
int result = 0; | |
Scanner sc = new Scanner(System.in); | |
String a = sc.next(); | |
String b = sc.next(); | |
for(int i=0; i<a.length(); i++) { | |
a1[i] = (int)a.charAt(i)-48; | |
} | |
for(int i=0; i<b.length(); i++) { | |
b1[i] = (int)b.charAt(i)-48; | |
} | |
if(a.length()>b.length()) { | |
result = 1; | |
}else if(a.length()==b.length()) { | |
for(int i=a.length(); i>0; i--) { | |
if(a1[i]>b1[i]) { | |
result =1; | |
break; | |
}else if(a1[i]==b1[i]) { | |
result =0; | |
}else { | |
result = 2; | |
break; | |
} | |
} | |
}else { | |
result = 2; | |
} | |
for(int i=2; i>=0; i--) { | |
if(result==1) { | |
System.out.print(a1[i]); | |
}else if(result==2){ | |
System.out.print(b1[i]); | |
} | |
} | |
} | |
} |
'백준 알고리즘 > JAVA' 카테고리의 다른 글
[JAVA 자바] 백준 2941번 크로아티아 알파벳 (0) | 2018.07.12 |
---|---|
[JAVA 자바] 백준 5622번 다이얼 (0) | 2018.07.12 |
[JAVA 자바] 백준 1011번 Fly me to the Alpha Centauri (2) | 2018.07.12 |
[JAVA 자바] 백준 1316번 그룹 단어 체커 (0) | 2018.07.11 |
[JAVA 자바] 백준 1193번 분수찾기 (0) | 2018.07.11 |