본문 바로가기

Problem Solving/백준

백준 2908 상수

반응형
2908 상수 문제

핵심적으로 스트링 클래스 메소드들을 활용해 문제의 조건들을 충족했다.

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
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        
       Scanner sc= new Scanner(System.in);
       
       String first = sc.nextLine();
       
       String second[] = first.split(" ");
       
       while(second[0].equals(second[1]) || second[0].length() != 3 || second[1].length() != 3 || second[0].contains("0"|| second[1].contains("0")) {
           first = sc.nextLine();
           second = first.split(" ");
       }//두수가 같거나 3자리수가 아닐경우 또는 0이 포함될경우 다시 반복한다.
     
       String output1[] = second[0].split("");
       String finals1= "";
       
       for(int i=output1.length-1; i>=0; i--) {
           finals1=finals1+output1[i];
       }
       
       String output2[] = second[1].split("");
       String finals2= "";
       
       for(int i=output2.length-1; i>=0; i--) {
           finals2=finals2+output2[i];
       }
       
        int front = Integer.parseInt(finals1);
        int rear  = Integer.parseInt(finals2);
        
        if(front > rear) {//큰것을 출력하자
            System.out.println(front);
        }
        else {
            System.out.println(rear);//큰것을 출력하자
        }
    }
}
cs


반응형

'Problem Solving > 백준' 카테고리의 다른 글

백준 2941번  (0) 2019.01.26
백준 1152번  (0) 2019.01.26
백준 1316번  (0) 2019.01.24
백준 10809번  (0) 2019.01.24
백준 1158 번  (0) 2019.01.06