首页 > ACM题库 > HDU-杭电 > HDU 1877 又一版 A+B[解题报告] C++
2013
12-23

HDU 1877 又一版 A+B[解题报告] C++

又一版 A+B

问题描述 :

输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m (1 < m <10)进制数。

输入:

输入格式:测试输入包含若干测试用例。每个测试用例占一行,给出m和A,B的值。
当m为0时输入结束。

输出:

输出格式:每个测试用例的输出占一行,输出A+B的m进制数。

样例输入:

8 1300 48
2 1 7
0

样例输出:

2504
1000

#include<iostream>
#include<stack>
using namespace std;
int m,a,b;
stack<int> p;
int main()
{
	int t;
	while(cin>>m)
	{
		if(!m) break;
		cin>>a>>b;
		a+=b;
		if(a==0) {cout<<0<<endl;continue;}
		while(a)
		{
			t=a%m;
			p.push(t);
			a/=m;
		}
		while(!p.empty())
		{
			cout<<p.top();
			p.pop();
		}
		cout<<endl;
	}
	return 0;
}

解题报告转自:http://blog.csdn.net/airuozhaoyang/article/details/17011007


  1. simple, however efficient. A lot of instances it is difficult to get that a??perfect balancea?? among usability and appearance. I must say that youa??ve done a exceptional task with this. Also, the blog masses quite fast for me on Web explore.