Too short in line 1

P1303 A*B Problem

cclianlian @ 2024-06-11 12:07:15

#include<bits/stdc++.h>
#define maxv 5550
using namespace std;
string A, B;
int a[maxv], b[maxv], res[maxv];
void solve() {
    cin >> A >> B;
    int lena = A.length(), lenb = B.length();
    for (int i = lena - 1; i >= 0; i--) {
        a[lena-i] = A[i] - '0';
    }
    for (int i = lenb - 1; i >= 0; i--) {
        b[lenb - i] = B[i] - '0';
    }
    //正序 1开始
    for (int i = 1; i <= lena; i++) {
        for (int j = 1; j <= lenb; j++) {
            res[i + j - 1] += a[i] * b[j];
        }
    }
    //进位
    for (int i = 1; i <= lena + lenb; i++) {        
        res[i + 1] +=res[i] / 10;
        res[i] %= 10;
    }
    int len = lena + lenb;
    for (; res[len] == 0;len--) {
    }
    for (int i = len; i >=1; i--) {
        cout << res[i];
    }

}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);
    solve();
}

by cclianlian @ 2024-06-11 12:07:41

总是有些莫名错误too short on line 1,


by xuchuhan @ 2024-06-11 12:59:59

@cclianlian Hack:

Input:
0
0

Output:
0

by cclianlian @ 2024-06-11 13:37:11

@xuchuhan 已解决,谢谢


|