POJ1546 & HDU 1335 & ZOJ 1334 Basically Speaking(进制转换)
2014-09-09 14:58
423 查看
题目链接:
POJ:http://poj.org/problem?id=1546
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1335
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=334
Description
The Really Neato Calculator Company, Inc. has recently hired your team to help design their Super Neato Model I calculator. As a computer scientist you suggested to the company that it would be neato if this new calculator could convert among number bases.
The company thought this was a stupendous idea and has asked your team to come up with the prototype program for doing base conversion. The project manager of the Super Neato Model I calculator has informed you that the calculator will have the following neato
features:
It will have a 7-digital display.
Its buttons will include the capital letters A through F in addition to the digits 0 through 9.
It will support bases 2 through 16.
Input
The input for your prototype program will consist of one base conversion per line. There will be three numbers per line. The first number will be the number in the base you are converting from. The second number is the base you are converting from. The third
number is the base you are converting to. There will be one or more blanks surrounding (on either side of) the numbers. There are several lines of input and your program should continue to read until the end of file is reached.
Output
The output will only be the converted number as it would appear on the display of the calculator. The number should be right justified in the 7-digit display. If the number is to large to appear on the display, then print ``ERROR'' (without the quotes) right
justified in the display.
Sample Input
Sample Output
Source
Mid-Central USA 1995
题意:
给出某一种进制的数,转换为另一种进制!
不管你认为它是不是很简单,反正我被坑了7个小时!
![](http://img.blog.csdn.net/20140909145735290?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjg2MDA2Mw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
代码如下:
POJ:http://poj.org/problem?id=1546
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1335
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=334
Description
The Really Neato Calculator Company, Inc. has recently hired your team to help design their Super Neato Model I calculator. As a computer scientist you suggested to the company that it would be neato if this new calculator could convert among number bases.
The company thought this was a stupendous idea and has asked your team to come up with the prototype program for doing base conversion. The project manager of the Super Neato Model I calculator has informed you that the calculator will have the following neato
features:
It will have a 7-digital display.
Its buttons will include the capital letters A through F in addition to the digits 0 through 9.
It will support bases 2 through 16.
Input
The input for your prototype program will consist of one base conversion per line. There will be three numbers per line. The first number will be the number in the base you are converting from. The second number is the base you are converting from. The third
number is the base you are converting to. There will be one or more blanks surrounding (on either side of) the numbers. There are several lines of input and your program should continue to read until the end of file is reached.
Output
The output will only be the converted number as it would appear on the display of the calculator. The number should be right justified in the 7-digit display. If the number is to large to appear on the display, then print ``ERROR'' (without the quotes) right
justified in the display.
Sample Input
1111000 2 10 1111000 2 16 2102101 3 10 2102101 3 15 12312 4 2 1A 15 2 1234567 10 16 ABCD 16 15
Sample Output
120 78 1765 7CA ERROR 11001 12D687 D071
Source
Mid-Central USA 1995
题意:
给出某一种进制的数,转换为另一种进制!
不管你认为它是不是很简单,反正我被坑了7个小时!
代码如下:
#include <cstdio> #include <cstring> #include <cmath> char s[117], ans[117]; int a, b; int k; int len; int check( char c) { if(c == 'A') return 10; else if(c == 'B') return 11; else if(c == 'C') return 12; else if(c == 'D') return 13; else if(c == 'E') return 14; else if(c == 'F') return 15; else return c-'0'; } char check1(int c) { if(c == 10) return 'A'; else if(c == 11) return 'B'; else if(c == 12) return 'C'; else if(c == 13) return 'D'; else if(c == 14) return 'E'; else if(c == 15) return 'F'; else return c+'0'; } int POW(int a, int len) { int ss = 1; for(int i = 0; i < len; i++) { ss*=a; } return ss; } void slove() { int r, tt = 0; for(int i = 0; i < len; i++) { tt += check(s[i])*pow(a*1.0,len-1-i); } //printf("tt:%d\n",tt); k = 0; while(tt) { r = tt%b; ans[k++] = check1(r); tt/=b; } } int main() { while(scanf("%s",s)!=EOF) { len = strlen(s); scanf("%d %d",&a,&b); slove(); if(k > 7) { printf(" ERROR\n"); continue; } for(int i = 1; i <= 7-k; i++) printf(" "); for(int i = k-1; i >= 0; i--) printf("%c",ans[i]); printf("\n"); } return 0; }
相关文章推荐
- poj 1543 & HDU 1334 & ZOJ 1331 Perfect Cubes(数学 暴力大法好)
- HDU 1335 || ZOJ 1334 Basically Speaking
- zoj 1002 && hdu 1045 Fire Net
- zoj 1334 Basically Speaking(进制转换)
- UVa 439/HDU 1372/POJ 2243/ZOJ 1091 Knight Moves(BFS&纯数学方法)
- hdu 4424 & zoj 3659 Conquer a New Region (并查集 + 贪心)
- 计算几何基础与应用:HDU 1348&&ZOJ 1648&&POJ 2398&&ZOJ 1010
- hdu 3714 && zoj 3203 三分
- Hdu 1059 Dividing & Zoj 1149 & poj 1014 Dividing(多重背包)
- Hdu 1242 & Zoj 1649 Rescue (优先队列+BFS)
- ZOJ 2619 && HDU 3058
- TOJ 1335 HDU 1242 ZOJ 1649 营救天使 / 广搜+优先队列
- HDU 1335 Basically Speaking【进制转换】
- ZOJ 4772 Treasure Hunt I 树形DP(背包) && hdu The Ghost Blows Light 树形DP(背包)
- UVa 442/HDU 1082/ZOJ 1094 Matrix Chain Multiplication(模拟&栈)
- ZOJ 3547 & HDU 4059
- Codeforces 136 divIID && zoj 3633 && HDU 4358
- HDU:2031 进制转换问题
- 8月10号的练习:ZOJ 3203&&POJ 3974&&HDU 1394&&HDU 3400&&HDU 2152
- Hdu 1059 Dividing & Zoj 1149 & poj 1014 Dividing(多重背包)