DALAO求调
  • 板块灌水区
  • 楼主yxShaw
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/8/17 09:16
  • 上次更新2024/8/17 11:29:50
查看原帖
DALAO求调
1021829
yxShaw楼主2024/8/17 09:16

P1001 A+B Problem

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>

using namespace std;

const int N = 260;

string s1, s2;
int a[N], b[N], c[N];
int la, lb, lc, m;

int main()
{
	ios::sync_with_stdio(0);
	cin >> s1 >> s2;
	la = s1.length(), lb = s2.length();
	for(int i = 0; i < la; i++)
		a[i] = s1[la - 1 - i] - '0';
	for(int i = 0; i < lb; i++)
		b[i] = s2[lb - 1 - i] - '0';
	if(la > lb) lc = la;
	else lc = lb;
	m = 0;
	for(int i = 0; i < lc; i++)
	{
		c[i] = (m + a[i] + b[i]) % 10;
		m = (m + a[i] + b[i]) / 10; 
	}
	if(m > 0)
	{
		c[lc] = m;
		lc++;	
	}
	for(int i = lc - 1; i >= 0; i--)
		cout << c[i];
	return 0;
}
2024/8/17 09:16
加载中...