牛牛经常在数学课上睡觉,所以他的数学非常烂。
别人的数学都是进位加法, 但是他的却是非进位加法,比如 7+7 = 4, 22+84 = 6
现在牛牛想考验你一下, 给你两个非常大的数,计算他们的和。
牛牛经常在数学课上睡觉,所以他的数学非常烂。
别人的数学都是进位加法, 但是他的却是非进位加法,比如 7+7 = 4, 22+84 = 6
现在牛牛想考验你一下, 给你两个非常大的数,计算他们的和。
第一行一个整数 a ( a ≥ 0 and |a| ≤ 2e5)第二行一个整数 b ( b ≥ 0 and |b| ≤ 2e5)
输出一个数 c , c = a + b
80 34
14
99 11
0
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main() {
    string a, b; cin >> a >> b;
    int la = a.size(), lb = b.size();
    string t = string(abs(la - lb), '0');
    if(a.size() > b.size()) {
        b = t + b;
    } else {
        a = t + a;
    }
    for(int i = 0; i < a.size(); i++) {
        a[i] = (a[i] - '0' + b[i] - '0') % 10 + '0';
    }
    //cerr << a << endl;
    bool f = false;
    for(int i = 0; i < a.size(); i++) {
        if(a[i] != '0') {
            f = true;
            a = a.substr(i);
            break;
        }
    }
    if(!f) a = "0";
    cout << a << endl;
    return 0;
}
                                                                                    import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.next();
        String b = in.next();
        
        StringBuilder x = new StringBuilder(a);
        StringBuilder y = new StringBuilder(b);
        StringBuilder sb = new StringBuilder();
        while (x.length() != 0 && y.length() != 0) {
            int i = x.charAt(x.length()-1)-'0';
            int j = y.charAt(y.length()-1)-'0';
            int ans = (i+j) % 10;
            x.delete(x.length()-1, x.length());
            y.delete(y.length()-1, y.length());
            sb.append(ans);
        }
        while (x.length() != 0) {
            int i = x.charAt(x.length()-1)-'0';
            x.delete(x.length()-1, x.length());
            sb.append(i);
        }
        while (y.length() != 0) {
            int j = y.charAt(y.length()-1)-'0';
            y.delete(y.length()-1, y.length());
            sb.append(j);
        }
        while (sb.length() > 0) {
            if (sb.charAt(sb.length() - 1) == '0') {
                sb.delete(sb.length() - 1, sb.length());
            } else {
                break;
            }
        }
        if (sb.length() == 0) {
            System.out.println("0");
        } else {
            System.out.println(sb.reverse().toString());
        }
    }
}