记录编号 453012 评测结果 AAAAAAAAAA
题目名称 增强的加法问题 最终得分 100
用户昵称 Gravatarexpletar 是否通过 通过
代码语言 C++ 运行时间 0.002 s
提交时间 2017-09-20 19:53:56 内存使用 0.32 MiB
显示代码纯文本
#include<fstream>
//#include<iostream>
#include<string>

using namespace std;

ofstream out ("add.out");
ifstream in ("add.in");

//auto &in=cin;
//auto &out=cout;

string s1,s2;

void late (string::reverse_iterator);

int main ()
{
	in>>s1>>s2;
	{}
	if (s1.length()<s2.length())
	{
		swap(s1,s2);
	}
	s1=string ("0")+s1;
	//pre
	for (string::iterator it = s1.begin();it!=s1.end();++it)
	{
		*it-='0';
	}
	for (string::iterator it = s2.begin();it!=s2.end();++it)
	{
		*it-='0';
	}
	//ed

	string::reverse_iterator it2=s1.rbegin();
	for (string::reverse_iterator it = s2.rbegin();it!=s2.rend();++it)
	{
		int a=*it+*it2;
		*it2=a%10;
		++it2;
		if (a>=10)
		{
		late (it2);
		}
	}
	if (*s1.begin()>0)
	{
		out<<int (*(s1.begin()));
		}
	for (string::iterator it = s1.begin ()+1;it!=s1.end();++it)
	{
		out<<int (*it);
		}
	
	return 0;
}

inline void late (string::reverse_iterator it)
{
	if (*it==9)
	{
		*it=0;
		late (++it);
	}
	else ++*it;
		
	return ;
}