Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Solution {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int T = sc.nextInt();
- for (int t = 1; t <= T; t++) {
- String a = sc.next();
- String b = sc.next();
- char[] ac = new char[101];
- char[] bc = new char[101];
- char[] cc = new char[101];
- for (int z = 0; z <= 100; z++) {
- ac[z] = '0';
- bc[z] = '0';
- cc[z] = '0';
- }
- for (int z = 0; z < a.length(); z++) {
- ac[100 - z] = a.charAt(a.length() - z - 1);
- }
- for (int z = 0; z < b.length(); z++) {
- bc[100 - z] = b.charAt(b.length() - z - 1);
- }
- int carry = 0;
- for (int z = 100; z >= 0; z--) {
- int sum = Character.getNumericValue(ac[z]) + Character.getNumericValue(bc[z]) + carry;
- if (sum >= 10) {
- cc[z] = (char) (sum % 10 + '0');
- carry = 1;
- } else {
- cc[z] = (char) (sum + '0');
- carry = 0;
- }
- }
- System.out.print("#" + t + " ");
- Boolean print = false;
- for (int z = 0; z <= 100; z++) {
- if (cc[z] != '0') {
- print = true;
- }
- if (print) {
- System.out.print(cc[z]);
- }
- }
- System.out.println();
- }
- sc.close();
- }
- }
Add Comment
Please, Sign In to add comment