12 条题解
-
3赵青海 (huhe) LV 7 SU @ 2021-11-6 20:57:28
/***************************************** 备注: ******************************************/ #include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; int x[N],y[N],z[N]; int main() { string a,b; cin >> a >> b; int lena = a.size(); int lenb = b.size(); for(int i = 0 ; i < lena ; i++) x[i] = a[lena - i - 1] - '0'; for(int i = 0 ; i < lenb ; i++) y[i] = b[lenb - i - 1] - '0'; for(int i = 0 ; i < lena ; i++) for(int j = 0 ;j < lenb ; j++) { z[i+j] += x[i] * y[j]; z[i+j + 1] += z[i+j]/10; z[i+j] %= 10; } int len = lena + lenb ; while( !z[len] && len > 0) len--; for(int i = len ; i >= 0 ; i--) cout << z[i]; return 0; }
-
12023-11-26 18:13:12@
#include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; }
-
02024-9-18 17:01:52@
#include <iostream> using namespace std; const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main(){ cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++){ a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++){ b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++){ x=0; for(int j=0;j<lena;j++){ c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0){ lenc--; } for(int i=lenc;i>=0;i--){ cout<<c1[i]; } return 0; }
-
02024-7-27 15:05:29@
#include<iostream> using namespace std; int main(){ string a1,b1; cin>>a1>>b1; int a[1000]={},b[1000]={},c[1000]={}; int lena=a1.size(),lenb=b1.size(); for(int i=1;i<=lena;i++) a[i]=a1[lena-i]-'0'; for(int i=1;i<=lenb;i++) b[i]=b1[lenb-i]-'0'; for(int i=1;i<=lena;i++){ int x=0; for(int j=1;j<=lenb;j++){ c[i+j-1]+=a[i]*b[j]+x; x=c[i+j-1]/10; c[i+j-1]%=10; } c[i+lenb]=x; } int lenc=lena+lenb; while(c[lenc]==0&&lenc>1) lenc--; for(int i=lenc;i>0;i--) cout<<c[i]; return 0; }
-
02024-3-17 15:47:14@
#include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; } #include <iostream> using namespace std; #define ll long long const int N =1e5+10; const int INF =0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin>>a>>b; lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++) { a1[i]=a[lena-i-1]-'0'; } for(int i=0;i<lenb;i++) { b1[i]=b[lenb-i-1]-'0'; } for(int i=0;i<lenb;i++) { x=0; for(int j=0;j<lena;j++) { c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) { lenc--; } for(int i=lenc;i>=0;i--) { cout<<c1[i]; } return 0; }
-
02024-3-17 15:43:31@
不是,看题解的都有啥实力锕
-
02023-12-5 16:52:28@
这道题其实和高精度加法很像,只要在高精度加法的基础上稍加修改就可以了。
上代码↓
#include<bits/stdc++.h> using namespace std; int c[100000]; int a1[100000],b1[100000]; int len1,len2,len3,x; string a,b; int r,y; int main(){ cin>>a>>b; len1=a.size(); len2=b.size(); for(int i=0;i<len1;i++)a1[i]=a[len1-i-1]-'0'; for(int i=0;i<len2;i++)b1[i]=b[len2-i-1]-'0'; for(int i=0;i<len1;i++){ for(int j=0;j<len2;j++){ c[i+j]+=a1[i]*b1[j]; c[i+j+1]+=c[i+j]/10; c[i+j]%=10; } } len3=len1+len2; while(c[len3]==0&&len3>0){ len3--; } for(int i=len3;i>=0;i--)cout<<c[i]; return 0; }
点个赞呗
-
02023-11-25 20:18:56@
#include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; string a,b; int a1[N],b1[N],c1[N],lena,lenb,lenc,x; int main() { cin >> a; cin >> b; lena = a.size(); lenb = b.size();
for(int i = 0;i <lena;i++) { a1[i]= a[lena-i-1] -'0'; } for(int i = 0;i <lenb;i++) { b1[i]= b[lenb-i-1] -'0'; } for(int i = 0;i < lenb;i++) { x =0; for(int j = 0;j < lena;j++) { c1[i + j]+=a1[j]* b1[i]+x; x = c1[i + h]/10; c1 [i+j]%=10; } c1[lena + i]=x; } lenc = lena +lenb; while(c1[lenc]==0&&lenc>0) lenc--; for(int i = lenc;i >= 0;i--) cout <<c1[i]; return 0;
}
-
02023-11-25 20:10:58@
#include <iostream> #include <iomanip> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; const int N =1e5+10; string a , b; int lena , lenb , lenc , a1[N] , b1[N] , c1[N] , x; int main() { cin>>a>>b; lena = a.size(); lenb = b.size(); for(int i = 1;i <= lena;i++) { a1[i] = a[lena - i] - '0'; } for(int i = 1;i <= lenb;i++) { b1[i] = b[lenb - i] - '0'; } for(int i = 1;i <= lenb;i++) { x = 0; for(int j = 1;j<= lena;j++) { c1[i + j - 1] += a1[j] * b1[i] + x; x = c1[i + j - 1] / 10; c1[i + j - 1] %= 10; } c1[i + lena] = x; } lenc = lena + lenb; while(c1[lenc] == 0 && lenc > 1) { lenc--; } for(int i = lenc;i >= 1;i--) { cout<<c1[i]; } return 0; }
-
[ ] > ````````````````````````````````````````````````````````````````````````````````````````````````**************
**************
**********
******
**
-
-
02023-10-29 20:27:29@
#include <bits/stdc++.h> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; int x[N],y[N],z[N]; int main() { string a,b; cin >> a >> b; int lena = a.size(); int lenb = b.size(); for(int i = 0 ; i < lena ; i++) x[i] = a[lena - i - 1] - '0'; for(int i = 0 ; i < lenb ; i++) y[i] = b[lenb - i - 1] - '0'; for(int i = 0 ; i < lena ; i++) for(int j = 0 ;j < lenb ; j++) { z[i+j] += x[i] * y[j]; z[i+j + 1] += z[i+j]/10; z[i+j] %= 10; } int len = lena + lenb ; while( !z[len] && len > 0) len--; for(int i = len ; i >= 0 ; i--) cout << z[i]; return 0; }
-
02023-10-25 19:47:16@
#include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; const int N=1e5+10; const int INF=0x3f3f3f3f; char a[N],b[N]; int a1[N],b1[N],c1[N],lenc,x; int main(){ cin>>a>>b; int lena=strlen(a); int lenb=strlen(b); for(int i=0;i<lena;i++) a1[i]=a[lena-i-1]-'0'; for(int j=0;j<lenb;j++) b1[j]=b[lenb-j-1]-'0';
for(int i=0;i<lenb;i++){ x=0; for(int j=0;j<lena;j++){ c1[i+j]+=a1[j]*b1[i]+x; x=c1[i+j]/10; c1[i+j]%=10; } c1[lena+i]=x; } lenc=lena+lenb; while(c1[lenc]==0&&lenc>0) lenc--; for(int i=lenc;i>=0;i--) cout<<c1[i]; return 0;
}
-
-42022-3-19 10:11:37@
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; char aa[N],bb[N],cc[N]; int a[N],b[N],c[N]; int main() { cin >> aa >> bb; int lena = strlen(aa); int lenb = strlen(bb); for(int i = 0;i < lena;i++) a[i] = aa[lena - i - 1] - '0'; for(int i = 0;i < lenb;i++) b[i] = bb[lenb - i - 1] - '0'; for(int i = 0;i < lena;i++) { for(int j = 0;j < lenb;j++) { c[i+j] +=a[i] * b[j]; if(c[i+j] > 9) { c[i+j+1]+= c[i+j]/10; c[i+j] = c[i+j]%10; } } } int len = lena +lenb; while(c[len] == 0 && len > 0) { len--; } for(int i = len;i >=0;i--) cout << c[i]; return 0; }
- 1
信息
- ID
- 1187
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- 递交数
- 546
- 已通过
- 165
- 上传者