uua___ @ 2024-05-15 17:31:31
#include<bits/stdc++.h>
using namespace std;
int a[1000000],b[1000000],c[1000000];
string x,y;
int la,lb,lc;
int main()
{
cin>>x>>y;
la=x.size();
lb=y.size();
for(int i=0;i<la;i++)
{
a[la-i]=x[i]-'0';
}
for(int i=0;i<lb;i++)
{
b[lb-i]=y[i]-'0';
}
lc=max(la,lb);
for(int i=1;i<=lc;i++)
{
c[i]+=a[i]+b[i];
c[i+1]=c[i]/10;
c[i]=c[i]%10;
}
if(c[lc+1]>0) lc++;
for(int i=lc;i>=1;i--)
{
cout<<c[i];
}
return 0;
}
by Crab_Tang @ 2024-05-15 17:39:11
@uua___ 一看你就是高精度写挂了。
by YONEX @ 2024-05-15 17:41:22
@Robots75 有没有可能是没有考虑负数 @uua___
by Crab_Tang @ 2024-05-15 17:43:51
@uua___ 不是,你这题有负数的大哥。你做高精度你去高精度A+b去;
by stylus @ 2024-05-15 17:58:03
@uua___ 不愧是牢大,so?
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
cin>>a>>b;
cout<<a+b<<endl;
return 0;
}
&
by ZiruiLIU @ 2024-05-30 20:20:30
如此简单的题,你整这么麻烦,我20秒就能手写完:
#include<bits/stdc++.h>
using namespase std;
int main(){
int a,b;
cin>>a>>b;
cout<<a+b;
return 0;
}
by heyuyan @ 2024-06-22 17:18:13
@ZiruiLIU 我也是
by mcturtle @ 2024-06-23 22:18:40
牢大,高精度是高精度,可是你忘判断负数了
by Andlewzheyao @ 2024-07-02 11:50:10
不是哥们,高精度也是这样写,牢大这次真坠机了
#include<bits/stdc++.h>
using namespace std;
int a[10000] = {0}, b[10000] = {0};
int main() {
string js1, js2;
cin >> js1 >> js2;
int len1 = js1.size(), len2 = js2.size();
for (int i = len1 - 1, j = 0; i >= 0; i--, j++) {
a[j] = js1[i] - '0';
}
for (int i = len2 - 1, j = 0; i >= 0; i--, j++) {
b[j] = js2[i] - '0';
}
int i = 0, x = 0;
while ( i <= len1 || i <= len2 ) {
b[i] += a[i] + x;
x = b[i] / 10;
b[i] %= 10;
i++;
}
b[i] = x;
while (b[i] == 0 && i != 0) i--;
for (int j = i; j >= 0; j--) {
cout << b[j];
}
cout << endl;
}