又一版 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

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <cmath>
 6 #include <cctype>
 7 #include <vector>
 8 #include <list>
 9 #include <deque>
10 #include <stack>
11 #include <queue>
12 #include <map>
13 #include <set>
14 #include <string>
15 #include <algorithm>
16 
17 
18 using namespace std;
19 
20 int main()
21 {
22 
23 
24 int i,j,k;
25 int n;
26 
27 while(scanf("%d",&n)!=EOF)
28 {
29     if(n==0)
30         break;
31 
32     int a,b;
33 
34 
35     scanf("%d%d",&a,&b);
36     
37 
38     unsigned int c=a+b;
39     if(c==0)
40     {printf("0\n");continue;}
41 
42 
43     stack<int>stk;
44 
45     while(stk.size())
46     {stk.pop();}
47 
48     while(c)
49     {
50         stk.push(c%n);
51         c/=n;
52     }
53 
54     while(stk.size())
55     {
56         printf("%d",stk.top());
57         stk.pop();
58     }
59 
60     puts("");
61 }
62 
63 
64 
65     
66 
67     
68 
69     return 0;
70 }

 

posted @ 2012-05-30 20:32  cseriscser  阅读(332)  评论(0编辑  收藏  举报