對於一個整數X,定義操作rev(X)爲將X按數位翻轉過來,並且去除掉前導0。例如:
如果 X = 123,則rev(X) = 321;
如果 X = 100,則rev(X) = 1.
現在給出整數x和y,要求rev(rev(x) + rev(y))爲多少?
輸入描述:
輸入爲一行,x、y(1 ≤ x、y ≤ 1000),以空格隔開。
輸出描述:
輸出rev(rev(x) + rev(y))的值
輸入例子:
123 100
輸出例子:
223
import java.util.Scanner;
public class Main {
private static int rev(int x) {
String str = String.valueOf(x);
String s = new StringBuilder(str).reverse().toString();
return Integer.parseInt(s);
}
public static void main(String[] arg) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int x = scan.nextInt();
int y = scan.nextInt();
x = rev(x);
y = rev(y);
System.out.println(rev(x + y));
}
scan.close();
}
}