(数组的应用二:高精度运算4.2.1)POJ 1504 Adding Reversed Numbers(将一个数取反)
package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class POJ_1504 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while(t>0){ String str1 = scanner.next(); String str2 = scanner.next(); //StringBuilder的reverse()方法能将一个字符串取反 StringBuilder sb1 = new StringBuilder(str1); StringBuilder sb2 = new StringBuilder(str2); //Integer.parseInt(str)..能去掉前置的无效0 int add1 = Integer.parseInt(sb1.reverse().toString()); int add2 = Integer.parseInt(sb2.reverse().toString()); int result = add1 + add2; String str3 = String.valueOf(result); StringBuilder sb3 = new StringBuilder(str3); System.out.println(Integer.parseInt(sb3.reverse().toString())); t--; } } }
补充:软件开发 , Java ,