輸入兩個不超過整型定義的非負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 main()
{
unsigned m,A,B;
stack<int> s;
while(cin >> m && m != 0)
{
cin >> A >> B;
int sum = A + B;
do
{
s.push(sum % m);
sum /= m;
}while(sum != 0);
while(!s.empty())
{
cout << s.top();
s.pop();
}
cout << endl;
}
return 0;
}