題目1089:數字反轉
阿新 • • 發佈:2019-02-01
import java.io.IOException; import java.io.FileReader; import java.io.BufferedReader; import java.util.Scanner; class Main { public static final boolean DEBUG = false; public static void main(String[] args) throws IOException { Scanner cin; String s1, s2; int n; if (DEBUG) { cin = new Scanner(new BufferedReader(new FileReader("d:\\OJ\\uva_in.txt"))); } else { cin = new Scanner(System.in); } n = cin.nextInt(); while (n-- > 0) { s1 = cin.next(); s2 = cin.next(); int a1 = Integer.parseInt(s1), a2 = Integer.parseInt(s2); int ans1 = a1 + a2; StringBuffer tmp1 = new StringBuffer(s1); StringBuffer tmp2 = new StringBuffer(s2); s1 = tmp1.reverse().toString(); s2 = tmp2.reverse().toString(); a1 = Integer.parseInt(s1); a2 = Integer.parseInt(s2); int ans2 = a1 + a2; s1 = new Integer(ans1).toString(); tmp1 = new StringBuffer(s1); s1 = tmp1.reverse().toString(); ans1 = Integer.parseInt(s1); if (ans1 == ans2) { System.out.println(tmp1.reverse().toString()); } else { System.out.println("NO"); } } } }