题解
2023-09-18 19:12:48
发布于:浙江
这道题十分深奥,因为作者可能会坑我们。所以,我们要用高精度。代码如下:
#include<bits/stdc++.h>
#define N 210
using namespace std;
int as[N],bs[N],lena,lenb;
string a,b;
int main(){
cin>>a>>b;
lena=a.size();
lenb=b.size();
for(int i=0;i<lena;i++)as[i]=a[lena-i-1]-'0';
for(int i=0;i<lenb;i++)bs[i]=b[lenb-i-1]-'0';
int length=max(lena,lenb);
for(int i=0;i<length;i++)as[i]+=bs[i];
for(int i=0;i<length;i++){
if(as[i]>9){
as[i+1]++;
as[i]-=10;
if(i==length-1)length++;
}
}
while(length&&as[length]==0)length--;
for(int i=length;i>=0;i--)cout<<as[i];
cout<<endl;
}
看完代码,加入我的团队吧!
中国人民解放军
全部评论 39
看我别忘了点赞哦~
2023-09-18 来自 浙江
146
原本两三行的代码
硬生生写到了几十行
不愧是大佬
(doge2023-09-25 来自 四川
1就这?????????????
#include<iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
#include<string>
#include<cstring>
#include<list>
#include<map>
#include<queue>
#include<iterator>
#include<stack>
using namespace std;#define ll long long
const int N = 1010;int RAND_1(ll a,ll b){
ll n = a + b;
return n;
}int RAND_2(string a, string b, int n[500], int m[500], int ans[501]){
for(int i = 0; i < a.size(); i++)
n[i] = a[a.size() - i - 1] - '0';
for(int i = 0; i < b.size(); i++)
m[i] = b[b.size() - i - 1] - '0';
int len_maxn = max(a.size(), b.size()) + 1;
for(int i = 0; i < len_maxn; i++)
{
ans[i] = n[i] + m[i] + ans[i];
if(ans[i] > 9)
{
ans[i + 1]++;
ans[i] = ans[i] % 10;
}
}
while(ans[len_maxn - 1] == 0 && len_maxn > 0) len_maxn--;
for(int i = len_maxn - 1; i >= 0; i--) cout << ans[i];
return 0;
}int RAND_3(ll a, ll b){
ll ans = 0;
for(int i = 0; i < a; i ++ ) {
ans ++;
}
for(int i = 0; i < b; i ++ ) {
ans ++;
}
return ans;
}int n[1010], m[1010],c[1010];
int main(){
srand(time(0));
ll a , b;
string z , y;
int x;
x = 1 + rand() % 3;
if(x == 1){
cin >> a >> b;
int ans = RAND_1(a,b);
cout << ans;
}
if(x == 2){
cin >> z >> y;
RAND_2(z , y , n , m, c);
}
if(x == 3){
cin >> a >> b;
int ans = RAND_3(a, b);
cout << ans;
}
return 0;
}2024-11-03 来自 广东
2(狗式点头)
2025-01-26 来自 浙江
0
还用高精度……
2023-09-18 来自 浙江
26,小号吸引流量
2025-06-29 来自 浙江
0
这个有意思,6
2023-09-18 来自 浙江
2大佬



2026-02-15 来自 江苏
1搞得我都懵了
1周前 来自 浙江
0
1周前 来自 河北
0方法没错
2026-04-04 来自 浙江
01234
2026-04-02 来自 浙江
0厉害
2026-03-28 来自 江苏
01
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
12026-03-22 来自 江苏
0?
2026-03-19 来自 浙江
0n
2026-03-14 来自 浙江
0ok
2026-03-12 来自 浙江
0ok
2026-03-12 来自 浙江
0ok
2026-03-10 来自 浙江
0@ppl_cjdst(92134) 你会坑他吗
2026-02-28 来自 上海
0想的可能也太多了
2026-02-26 来自 福建
06666666666666
#include <bits/stdc++.h>
int main(){
long long a,b; stdcin>>a>>b; stdcout<<a+b;
}2026-02-23 来自 浙江
0ok
2026-02-12 来自 浙江
0#include<bits/stdc++.h> using namespace std; int main(){ string a,b,c=""; cin>>a>>b; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); int h=0,l=max(a.size(),b.size()),s1=a.size(),s2=b.size(); for(unsigned int i=0;i<l||h;i++){ int s=h; if(i<s1)s+=a[i]-'0'; if(i<s2)s+=b[i]-'0'; h=s/10; c+=((s%10)+'0'); } reverse(c.begin(),c.end()); int k=0,ll=c.size(); while(k<l-1&&c[k]=='0')k++; c.erase(0,k); cout<<c; return 0; }2025-12-29 来自 广东
0














































有帮助,赞一个