我這裡使用StringBuilder去reverse然後相加
程式碼如下:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class c304 {
/* 0.8s 15.1MB */
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String n;
while ((n = br.readLine()) != null)
rev(n);
} catch (Exception e) {
System.out.println();
}
}
static long rev(String n) {
StringBuilder sb = new StringBuilder(n);
String s = sb.reverse().toString();
long res = Long.parseLong(s);
res += Long.parseLong(n);
System.out.println(res);
return res;
}
}