为什么P1601那道题的高精度复制到这里会wa呢?

P1001 A+B Problem

chen111228 @ 2024-01-01 16:56:43

#include<iostream>
#include<string>
using namespace std;

const int N = 510;
int a[N], b[N], c[N];
int main()
{
    string str1;
    string str2;
    cin >> str1;
    cin >> str2;
    for (int i = 0; i < str1.size(); i ++)
        a[str1.size()-1 - i] = str1[i] - '0';
    for (int i = 0; i < str2.size(); i ++)
        b[str2.size()-1 - i] = str2[i] - '0';
    int ans = max(str1.size(), str2.size());
    for (int i = 0; i < ans; i ++){
        c[i] += a[i] + b[i];
        c[i+1] = c[i] / 10;
        c[i] %= 10;
    }
    ans += 1;
    if (c[ans-1] == 0 && ans > 1)
        ans -= 1;
    for (int i = 0; i < ans; i ++)
        cout << c[ans-1-i];
    return 0;
}

by Genius_physicist @ 2024-01-31 13:51:38

什么,有这么难的吗??


by yinjiayu @ 2024-01-31 20:31:32

@chen111228 望丰展?使markdown


by yiming_328 @ 2024-05-02 21:05:53

@wenmuchen105 等我长大了,一定要买一台能看到别人D盘里照片的电脑


上一页 |