C2024_QAQ @ 2024-07-20 16:41:02
有木有大神看看我的奇妙解法,实在是太难受了
#include<bits/stdc++.h>
#define _MAX 100001
using namespace std;
typedef long long ll;
ll l1,l2;
string s1,s2;
ll a1[_MAX],a2[_MAX],h[_MAX];
int main(){
cin>>s1>>s2;
if(s1.size()<s2.size()) swap(s1,s2);
l1=s1.size(),l2=s2.size();
for(int i=0;i<l1;i++) a1[i+1]=s1[i]-'0';
for(int i=l1-l2;i<l1;i++) a2[i+1]=s2[i-l1+l2]-'0';
for(int i=l1;i>=0;i--){
if(a1[i]+a2[i]>=10) {
h[i]=a1[i]+a2[i]-10;
a1[i-1]+=1;
if(i-1==0) a1[0]=1;
}
else h[i]=a1[i]+a2[i];
}
if(h[0]!=0) for(int i=0;i<=l1;i++) cout<<h[i];
else for(int i=1;i<=l1;i++) cout<<h[i];
return 0;
}
传送门
by XuYueming @ 2024-07-20 16:45:10
@C2024_QAQ 还奇妙解法,这不就是高精度吗?(无恶意)你没判负数
by C2024_QAQ @ 2024-07-20 16:46:39
好吧,我好想知道了,这个有负数
by C2024_QAQ @ 2024-07-20 16:49:09
But,请问我要怎么修改才能对
by CHGM @ 2024-07-20 16:56:22
@C2024_QAQ 开long long 会棕名吗?
by heyichen201209 @ 2024-07-20 17:11:32
@CHGM ?
by heyichen201209 @ 2024-07-20 17:18:37
@C2024_QAQ 高精度逝罢
by heyichen201209 @ 2024-07-20 17:21:16
@C2024_QAQ
#include<bits/stdc++.h>
using namespace std;
int main(){
string a,b;
cin>>a>>b;
int a1[100],b1[100],c1[101],x=0;
memset(a1,0,sizeof(a1));
memset(b1,0,sizeof(b1));
memset(c1,0,sizeof(c1));
for(int i=1;i<=a.size();i++)
a1[i]=a[a.size()-i]-48;
for(int i=1;i<=b.size();i++)
b1[i]=b[b.size()-i]-48;
int i=1;
while(i<=a.size()||i<=b.size()){
c1[i]=(a1[i]+b1[i]+x)%10;
x=(a1[i]+b1[i]+x)/10;
i++;
}
if(x==1){
c1[i]=1;
i++;
}
for(int j=i-1;j>=1;j--)
cout<<c1[j];
return 0;
}
by C2024_QAQ @ 2024-07-20 18:12:23
@heyichen201209 谢谢
by C2024_QAQ @ 2024-07-20 18:15:18
@heyichen201209 但是……还是错的,错的还是那几个点
by CHGM @ 2024-07-21 08:13:35
@C2024_QAQ 那就开long long啊!int 都能过