模拟 20pts 求条qwq
查看原帖
模拟 20pts 求条qwq
636358
WindyDay楼主2023/2/19 15:55

rt, \texttt{rt, } 模拟做的,20

#include <iostream>
#include <string>
using namespace std;

string myPlus(string x, string y)
{
	if(x.size() < y.size())
	{
		swap(x, y);
	}
	int sx = x.size();
	int sy = y.size();
	for(int i = 1; i <= sx - sy; i++)
	{
		y = "0" + y;
	}
			cout << x << " " << y << endl;
	int a[15], b[15];
	int j[15];
	//cout << x.size() << endl;
	for(int i = 0; i < x.size(); i++)
	{
		a[i + 1] = x[i] - '0';
		b[i + 1] = y[i] - '0';
		//cout << a[i + 1] << " % " << b[i + 1] << endl;
	}
	a[0] = 0;
	b[0] = 0;
	string c = "";
	j[x.size()] = 0;
	for(int i = x.size(); i >= 1; i--)
	{
		if(a[i] + b[i] + j[i] >= 14)
		{
			j[i - 1] = 2;
		}
		else if(a[i] + b[i] + j[i] >= 7)
		{
			j[i - 1] = 1;
		}
		else
		{
			j[i - 1] = 0;
		}
		c = char((a[i] + b[i] + j[i]) % 10 + int('0')) + c;
				cout << a[i] << " " << b[i] << " " << j[i] << endl;
		//cout << c << endl;
	}
	if(j[0])
	{
		c = char(j[0] + '0') + c;
	}
	cout << c << endl;
	return c;
}

int main()
{
	int n;
	cin >> n;
	string ans = "0";
	for(int i = 1; i <= n; i++)
	{
		string t;
		cin >> t;
		ans = myPlus(ans, t);
		cout << endl;
	}
	cout << ans << endl;
	return 0;
}

2023/2/19 15:55
加载中...