package org.example.test;

public class StringTest {
    public static void main(String[] args) {
        System.out.println(('1' - '0') + ('1' - '0'));
        solve("1", "99");
    }

    /**
     * 用tmp 临时保存进位 char变int '1' - '0'
     * @param s
     * @param t
     * @return
     */
    public static String solve(String s, String t) {
        // write code here
        int i = s.length() - 1;
        int j = t.length() - 1;
        int tmp = 0;
        StringBuilder sb = new StringBuilder();
        for (; i >= 0 && j >= 0; i--, j--) {
            int a = s.charAt(i) - '0';
            int b = t.charAt(j) - '0';
            int sum = a + b + tmp;
            if (sum >= 10) {
                tmp = 1;
                sb.append(sum % 10);
            } else {
                tmp = 0;
                sb.append(sum);
            }
        }
        while (i >= 0) {
            int a = s.charAt(i) - '0';
            int sum = tmp + a;
            if (sum >= 10) {
                tmp = 1;
                sb.append(sum % 10);
            } else {
                tmp = 0;
                sb.append(sum);
            }
            i--;
        }
        while (j >= 0) {
            int a = t.charAt(j) - '0';
            int sum = tmp + a;
            if (sum >= 10) {
                tmp = 1;
                sb.append(sum % 10);
            } else {
                tmp = 0;
                sb.append(sum);
            }
            j--;
        }
        if (tmp == 1) {
            sb.append(1);
        }
        return sb.reverse().toString();
    }

}