错了求调!!
查看原帖
错了求调!!
433237
Patrick_Jiang楼主2025/7/25 12:49

为哈错了?高精不对吗?

#include<bits/stdc++.h>
#define l length
#define r reverse
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	r(a.begin(), a.end());
    r(b.begin(), b.end());
    while(a.l()>b.l()) b+="0";
    while(b.l()>a.l()) a+="0";
    int c=0;
    string re="";
    for (int i=0;i<a.l();i++)
	{
        int sum=(a[i]-'0')+(b[i]-'0')+c;
        re+=to_string(sum%10);
        c=sum/10;
    }
    if(c>0) re+=to_string(c);
    r(re.begin(),re.end());
    cout<<re<<endl;
	return 0;
}
2025/7/25 12:49
加载中...