JOJ 1006解题
2012-07-30 15:35
246 查看
1006: All your base
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
3s | 8192K | 6195 | 2080 | Standard |
Input
Three positive integers denoting the base and the two numbers, respectively. Input numbers will be integers between 0 and 65535. Bases will be between 2 and 10 inclusive. Each case will be on a separate line. The end of input will be denoted by three zeros.Output
An equation for the sum of the two numbers, in the new base.Example
In this example, we add 10 and 3 in base 2, and we add 15 and 4 in base 3.In base 2, 10 = 8 + 2 = 1*23 + 0*22 + 1*21 + 0*20 and 3 = 2 + 1 = 1*21 + 1*20, so their base 2 equivalents are 1010 and 11, respectively. 10 + 3 = 13 = 1*23+1*22+0*21+1*20,
so the base 2 equivalent of 13 is 1101.
In base 3, 15 = 9 + 6 = 1*32+2*31+0*30 and 4 = 3 + 1 = 1*31 + 1*30, so their base 2 equivalents are 120 and 11, respectively. 15 + 4 = 19 = 2*32 + 0*31 + 1*30, so the
base 3 equivalent of 19 is 201.
Input
2 10 3 3 15 4 0 0 0
Output
1010 + 11 = 1101 120 + 11 = 201
解题代码如下:
#include <iostream> #include <stack> #include <queue> #include <vector> using namespace std; typedef struct{ int a ; int b ; int c ; }inputNum; void converse(int base, int num, stack<char> *result) { int a = num; int b = base; while (a != 0) { result->push(a%b + '0'); a = a/b; } } int main () { queue<inputNum> input; int a,b,c; while(cin>>a>>b>>c && !(a == 0 && b == 0 && c == 0)) { inputNum temp; temp.a = a; temp.b = b; temp.c = c; input.push(temp); } while (!input.empty()) { inputNum temp ; temp = input.front(); input.pop(); stack<char> result; converse(temp.a, temp.b, &result); stack<char> result2; converse(temp.a, temp.c, &result2); stack<char> result3; converse(temp.a, temp.b+temp.c , &result3); while (!result.empty()) { cout<<result.top(); result.pop(); } cout << " + "; while (!result2.empty()) { cout<<result2.top(); result2.pop(); } cout <<" = "; while (!result3.empty()) { cout<<result3.top(); result3.pop(); } cout<<endl; } return 0; }
相关文章推荐
- JOJ 1006解题
- JOJ 1054: Area 解题报告
- pku 1006 解题报告
- 2012 ACM/ICPC Asia Regional Tianjin Online 1006_you are the one 解题报告
- JOJ 1061: Rank The Teams 解题报告
- JOJ 1073: Piggy-Bank 解题报告
- POJ1006 Biorhythms 解题报告
- [PAT (Advanced Level) ]1006. Sign In and Sign Out解题文档
- 2017百度之星初赛(A)1001,1005,1006解题报告
- JOJ 1055: Cog-Wheels 解题报告
- PAT (Advanced Level) 1006. Sign In and Sign Out (25) 解题报告
- Sicily 1006. Team Rankings 解题报告
- POJ 1006 Biorhythms 解题报告(中国剩余定理)
- JOJ 2558 / HDU 2757 (Ocean Currents) 解题纠错
- YT02-简单数学课后题-1006 抱歉 -(5.31日-烟台大学ACM预备队解题报告)
- YT04-贪心课后练习-1006—PAINTER(6.14日-烟台大学ACM预备队解题报告)
- JOJ 1060: Time And Motion 解题报告
- ZOJ1006解题报告
- 2013年4月_武科大程序设计大赛(复赛)_解题报告(problem 1006)
- JOJ 1063: A Funny Game 解题报告