1. 程式人生 > >【簡單】數字翻轉

【簡單】數字翻轉

對於一個整數X,定義操作rev(X)為將X按數位翻轉過來,並且去除掉前導0。例如:
如果 X = 123,則rev(X) = 321;
如果 X = 100,則rev(X) = 1.
現在給出整數x和y,要求rev(rev(x) + rev(y))為多少?

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static int revs(int x){
        int d;
        int ans=0;
        while
(x!=0){ d = x % 10; ans = ans*10+d; x = x/10; } return ans; } public static int rev(int x){ StringBuffer sc = new StringBuffer(String.valueOf(x)); sc = sc.reverse(); return Integer.valueOf(sc.toString()); } public
static void main(String[] args) { // TODO Auto-generated method stub Scanner cin = new Scanner(System.in); while(cin.hasNext()){ int x = cin.nextInt(); int y = cin.nextInt(); System.out.println(revs(revs(x)+revs(y))); } } }