30 条题解
-
-1黎曜荣 (liyaorong) LV 5 @ 2023-10-18 20:27:46
#include<bits/stdc++.h> 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';
lenc=max(lena,lenb); for(int i=0;i<lenc;i++){ c1[i]=a1[i]+b1[i]+x; x=c1[i]/10; c1[i]%=10; } c1[lenc]=x; while(c1[lenc]==0&&lenc>0) lenc--; for(int i=lenc;i>=0;i--){ cout<<c1[i]; } return 0;
}
-
-12023-5-2 20:55:19@
#include<iostream> using namespace std; string s1,s2; int a[505],b[505],c[505]; int la,lb; int main() { cin >> s1 >> s2; la = s1.size(); lb = s2.size(); for(int i = 0; i < la;i++) a[la - i] = s1[i] - '0'; for(int i = 0; i < lb;i++) b[lb - i] = s2[i] - '0'; int lc = max(la,lb)+1; for(int i=1;i <= lc;i++) { c[i] += a[i] +b[i]; c[i + 1 ] = c[i]/10;\ c[i] %= 10; } while(c[lc] == 0 && lc > 1)lc--; for(int i = lc; i >= 1; i--) cout << c[i]; return 0; }
-
-12023-4-30 10:15:57@
#include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> #include<bits/stdc++.h> using namespace std; int a[510],b[510],c[510]; int la,lb; string s1,s2; ; int main(){ cin >> s1 >> s2; la=s1.size(); lb=s2.size(); for (int i=0; i<la; i++){ a[la-i]=s1[i]-'0'; } for (int i=0; i<lb; i++){ b[lb-i]=s2[i]-'0'; } int lc = max(la,lb)+1; for (int i=1; i<=lc; i++){ c[i]+=a[i]+b[i]; c[i+1]=c[i]/10; c[i]%=10; } while(c[lc]==0&&lc>1)lc--; for (int i=lc; i>=1; i--)cout <<c[i]; return 0; }
-
-12023-4-30 10:10:12@
#inlude<iostream> using namespace std; string s1,s2; int a[505],b[505],c[505]; int la,lb; int main() { cin >> s1 >> s2; la = s1.size(); lb = s2.size(); for(int i = 0; i < la;i++) a[la - i] = s1[i] - '0'; for(int i = 0; i < lb;i++) b[lb - i] = s2[i] - '0'; int lc = max(la,lb)+1; for(int i 1;i <= lc;i++) { c[i] += a[i] +b[i]; c[i + 1 ] = c[i]/10;\ c[i] %= 10; } while(c[lc] == 0 && lc > 1)lc--; for(int i = lc; i >= 1; i--) cout << c[i]; return 0; }
-
-12022-3-19 9:50:54@
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; int main() { char aa[1000],bb[1000],cc[1000]; cin >> aa >> bb; int a[1000],b[1000],c[1000]; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); 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'; int len = max(lena,lenb); for(int i = 0;i < len;i++) { c[i] +=a[i] + b[i]; if(c[i] > 9) { c[i+1]+= c[i]/10; c[i]%=10; } } if(c[len]!=0) len++; for(int i= len - 1;i >=0;i--) cout << c[i]; return 0; }
-
-12021-11-6 20:56:05@
/***************************************** 备注: ******************************************/ #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 a[N] ,b[N] ,c[N]; int main() { string aa,bb; cin >> aa >> bb; int lena = aa.size(); int lenb = bb.size(); for(int i = 0 ; i < lena ; i++) a[ lena- 1 - i ] = aa[i] - '0'; for(int i = 0 ; i < lenb ; i++) b[ lenb- 1 - i ] = bb[i] - '0'; // 数字对齐的过程 int len = max(lena , lenb); for(int i = 0 ; i < len ; i++) { c[i] += a[i] + b[i]; if(c[i] > 9) { c[i+1]++; c[i] -= 10; } } if(c[len] != 0) len++; for(int i = len - 1; i >= 0 ;i--) cout <<c[i]; return 0; }
-
-32023-3-1 22:32:19@
#include <bits/stdc++.h> using namespace std; const int maxn = 550; char sa[maxn],sb[maxn]; int a[maxn],b[maxn],c[maxn]; int main(){ scanf("%s",sa); scanf("%s",sb); memset(c,0,sizeof(c)); int la = strlen(sa); int lb = strlen(sb); for(int i = 0 ; i < la ; i++) a[la - i - 1] = sa[i] - '0'; for(int i = 0 ; i < lb ; i++) b[lb - i - 1] = sb[i] - '0'; int lc = la > lb ? la : lb; for(int i = 0 ; i < lc ; i++){ c[i] += a[i] + b[i]; if(c[i] >= 10){ c[i+1] = c[i]/10; c[i] = c[i]%10; } } if(c[lc] > 0) lc++; int cnt = lc - 1; while(c[cnt] == 0) cnt--; for(int i = cnt ; i >= 0 ; i--) printf("%d",c[i]); return 0; }
-
-32021-11-6 20:53:35@
#include<iostream> using namespace std; int a[100010],b[100010],c[100010]; int main() { string aa,bb; cin>>aa>>bb; int lena=aa.size(); int lenb=bb.size(); for(int i=0;i<lena;i++) a[lena-1-i]=aa[i]-'0'; for(int i=0;i<lenb;i++) b[lenb-1-i]=bb[i]-'0'; int len=max(lena,lenb); for(int i=0;i<len;i++) { c[i]+=a[i]+b[i]; if(c[i]>9) { c[i+1]++; c[i]-=10; } } if(c[len]!=0) len++; for(int i=len-1;i>=0;i--) cout<<c[i]; return 0; }
-
-32021-11-6 20:34:05@
#include<iostream> using namespace std; int main() { int a,b,c; cin>>a>>b; c=a+b; cout<<c<<endl; }
-
-42021-11-15 17:46:26@
#include <iostream> #include <cstring> using namespace std; int main() { string a,b; cin >> a >> b; int x[1000],y[1000]; memset(x,0,sizeof(x)); memset(y,0,sizeof(y)); int lena=a.size(); int lenb=b.size(); for(int i = 0; i < lena; i++)x[i]=a[lena-1-i]-'0'; for(int i = 0; i < lenb; i++)y[i]=b[lenb-1-i]-'0'; int len = lena > lenb ? lena : lenb; for(int i = 0; i < len ; i++){ x[i]+=y[i]; x[i+1]+=x[i]/10; x[i]%=10; } if(x[len])len++; for(int i = len - 1; i >= 0; i--){ cout << x[i]; } }
信息
- ID
- 1190
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 7
- 标签
- 递交数
- 933
- 已通过
- 228
- 上传者