文章

59

粉丝

0

获赞

246

访问

5.4k

头像
大整数加法 题解:reverse+add
P1474 武汉大学机试题
发布于2026年3月11日 14:38
阅读数 102

#include <bits/stdc++.h>
using namespace std;

int main()
{
	string a,b;
	while(cin>>a>>b)
	{
		reverse(a.begin(),a.end());
		reverse(b.begin(),b.end());
		int put=0;
		int flag=0;
		for(int i=0;i<a.size();i++)
		{
			put+=(a[i]-'0'+b[i]-'0');
			a[i]=put%10+'0';
			put/=10;
		}
		if(put!=0)
			cout<<put;
		reverse(a.begin(),a.end());
		cout<<a<<endl;
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发