解题思路:
注意事项:
参考代码:
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String a = sc.next(); String b = sc.next(); String[] a1 = a.split(","); String[] b1 = b.split(","); int num_a = 0; int num_b = 0; boolean flag = a1[0].charAt(0) == '-'; boolean flag2 = b1[0].charAt(0) == '-'; for (int i = 0; i < a1.length; i++) { if (flag) { if (i == 0){ a1[i] = a1[i].substring(1); } num_a -= (int) (Integer.parseInt(a1[i]) * Math.pow(10, 3 * (a1.length - i - 1))); } else { num_a += (int) (Integer.parseInt(a1[i]) * Math.pow(10, 3 * (a1.length - i - 1))); } } for (int i = 0; i < b1.length; i++) { double pow = Math.pow(10, 3 * (b1.length - i - 1)); if (flag2) { if (i == 0){ b1[i] = b1[i].substring(1); } num_b -= (int) (Integer.parseInt(b1[i]) * pow); } else { num_b += (int) (Integer.parseInt(b1[i]) * pow); } } System.out.println(num_a + num_b); } } }
0.0分
0 人评分
C语言训练-自由落体问题 (C语言代码)浏览:650 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:537 |
1048题解(读入回车问题)浏览:628 |
矩形面积交 (C语言代码)浏览:1433 |
A+B for Input-Output Practice (I) (C语言代码)浏览:451 |
分解质因数 (C++代码)浏览:1561 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:487 |
1202题解浏览:689 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:727 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:550 |