[백준] 1357번 : 뒤집힌 덧셈 - Java(자바)

강재원·2022년 10월 17일
0

[코딩테스트] Java

목록 보기
118/200



https://www.acmicpc.net/problem/1357

import java.util.Scanner;
public class Main {
    static int Rev(int n){
        int num=0;
        if(n<10) num=n;
        else if(n<100){
            int a=n%10;
            int b=n/10;
            num=a*10+b;
        }
        else if(n<1000){
            int a=n%10;
            n/=10;
            int b=n%10;
            n/=10;
            int c=n%10;
            num=a*100+b*10+c;
        }
        else if(n<10000){
            int a=n%10;
            n/=10;
            int b=n%10;
            n/=10;
            int c=n%10;
            n/=10;
            int d=n%10;
            num=a*1000+b*100+c*10+d;
        }
        return num;
    }
    
    public static void main(String args[]) {
        Scanner s= new Scanner(System.in);
        int x=s.nextInt();
        int y=s.nextInt();
        System.out.format("%d",Rev(Rev(x)+Rev(y)));
    }
}
profile
개념정리 & 문법 정리 & 알고리즘 공부

0개의 댓글