20pts求助
查看原帖
20pts求助
824363
细数繁星楼主2023/7/8 09:20
// Problem: 
//     P1581 A+B Problem(升级版)
//   
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1581
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
string source;
int prime[10] = {
	2,
	3,
	5,
	7,
	11,
	13
};
int a[7], b[7], c[7];
int lena = 0, lenb = 0;
int main()
{
	cin >> source;
	bool isb = 0;
	for (int i = 0; i < source.size(); i++)
	{
		if (source[i] == '+')
		{
			isb = 1;
			continue;
		}
		if (source[i] == ',')	continue;
		if (!isb)
		{
			a[lena] = source[i] - '0';
			lena++;
		}
		if (isb)
		{
			b[lenb] = source[i] - '0';
			lenb++;
		}
	}
	reverse(a, a + lena);
	reverse(b, b + lenb);
	int lenc;
	for (lenc = 0; lenc < max(lena, lenb); lenc++)
	{
		c[lenc] = a[lenc] + b[lenc];
		c[lenc + 1] += c[lenc] / prime[lenc];
		c[lenc] %= prime[lenc];
	}
	lenc++;
	while (!c[lenc] && lenc > 0)	lenc--;
	for (; lenc >= 0; lenc--)
	{cout << c[lenc]; if (lenc != 0)cout << ",";}
	
}
2023/7/8 09:20
加载中...