1 条题解

  • -1
    @ 2023-7-22 7:48:44
    #include <cstdio>
    #include <string>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int MAXN = 1005;
    int i, an[MAXN], bn[MAXN], cn[MAXN], sum[MAXN + 10];
    int main() {
    	freopen("abc.in", "r", stdin);
    	freopen("abc.out", "w", stdout);
    	string a, b, c;
    	cin >> a >> b >> c;
    	int al = a.length(), bl = b.length(), cl = c.length();
    	int len = max({al, bl, cl});
    	for (i = al - 1; i >= 0; i--) an[al - i - 1] = a[i] - 48;
    	for (i = bl - 1; i >= 0; i--) bn[bl - i - 1] = b[i] - 48;
    	for (i = cl - 1; i >= 0; i--) cn[cl - i - 1] = c[i] - 48;
    	for (i = 0; i < len; i++) {
    		sum[i] += an[i] + bn[i] + cn[i];
    		sum[i + 1] += sum[i] / 10;
    		sum[i] %= 10;
    	}
    	if (sum[len]) len++;
    	for (i = len - 1; i >= 0; i--) printf("%d", sum[i]);
    	return 0;
    }
    
    • 1

    信息

    ID
    426
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    146
    已通过
    28
    上传者