【Luogu1303】【模板】A*B Problem

problem

solution

codes

#include<iostream>
#include<algorithm>
#include<string>
#define maxn 100001
using namespace std;
int a[maxn], b[maxn], c[maxn];
int main(){
    string s1, s2;
    cin>>s1>>s2;
    a[0]=s1.size(); b[0]=s2.size(); c[0]=a[0]+b[0]+1;
    for(int i = 1; i <= a[0]; i++)a[i] = s1[a[0]-i]-'0';
    for(int i = 1; i <= b[0]; i++)b[i] = s2[b[0]-i]-'0';
    for(int i = 1; i <= a[0]; i++){
        for(int j = 1; j <= b[0]; j++){
            c[i+j-1] += a[i]*b[j];
            if(c[i+j-1] >= 10){
                c[i+j] += c[i+j-1]/10;
                c[i+j-1] %= 10;
            }
        }
    }
    while(c[0]>1 && c[c[0]]==0)c[0]--;
    for(int i = c[0]; i >= 1; i--)
        cout<<c[i];
    return 0;
}
原文地址:https://www.cnblogs.com/gwj1314/p/9444669.html