【Luogu1303】【模板】A*B Problem

xiaoxiao2021-02-28  35

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.6miu.com/read-2613772.html

最新回复(0)