高精加 压位
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<cmath>#define LL long longusing namespace std;int a[1000],b[1000],c[1000];char s1[1001],s2[1001];int main(){ scanf("%s%s",s1,s2); int l1=strlen(s1); int l2=strlen(s2); int la=1,lb=1,k=1; for(int i=1;i<=l1;i++) { if(k==10000)la++,k=1; a[la]+=k*(s1[l1-i]-'0'); k*=10; } k=1; for(int i=1;i<=l2;i++) { if(k==10000)lb++,k=1; b[lb]+=k*(s2[l2-i]-'0'); k*=10; } k=0; for(int i=1;i<=max(la,lb)+1;i++){ c[i]=a[i]+b[i]+k; if(c[i]>=10000) k=c[i]/10000; else k=0; c[i]%=10000; } int lc=max(la,lb)+1; while(c[lc]==0&&lc>1) lc--; PRintf("%d",c[lc]); for(int i=lc-1;i>=1;i--) printf("%04d",c[i]); return 0;}高精乘 普通
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<cmath>#define LL long longusing namespace std;int a[1000],b[1000],c[1000];char s1[1001],s2[1001];int main(){ scanf("%s%s",s1,s2); int la=strlen(s1); int lb=strlen(s2); for(int i=0;i<la;i++)a[la-i]=s1[i]-48; for(int i=0;i<lb;i++)b[lb-i]=s2[i]-48; for(int i=1,x;i<=la;i++) { x=0; for(int j=1;j<=lb;j++) { c[i+j-1]=a[i]*b[j]+c[i+j-1]+x; x=c[i+j-1]/10; c[i+j-1]%=10; } c[i+lb]+=x; } int len=la+lb; while(c[len]==0&&len>1) len--; for(int i=len;i>=1;i--) printf("%d",c[i]); puts(""); return 0; }高精乘 压位
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<cmath>#define LL long longusing namespace std;LL a[10000],b[10000],c[10000];//数组一开始开小了 char s1[10010],s2[10010];int main(){ scanf("%s%s",s1,s2); int l1=strlen(s1); int l2=strlen(s2); int la=1,lb=1,k=1; for(int i=1;i<=l1;i++) { if(k==1000)la++,k=1; a[la]+=k*(s1[l1-i]-'0'); k*=10; } k=1; for(int i=1;i<=l2;i++) { if(k==1000)lb++,k=1; b[lb]+=k*(s2[l2-i]-'0'); k*=10; } for(int i=1,x;i<=la;i++) { x=0; for(int j=1;j<=lb;j++) { c[i+j-1]=a[i]*b[j]+c[i+j-1]+x; x=c[i+j-1]/1000; c[i+j-1]%=1000; } c[i+lb]+=x; } int lc=la+lb; while(c[lc]==0&&lc>1) lc--; printf("%d",c[lc]); for(int i=lc-1;i>=1;i--) printf("%03d",c[i]); puts(""); return 0; }新闻热点
疑难解答