POJ 1220 NUMBER BASE CONVERSION 高精度进制转换
2015-08-16 17:05
309 查看
poj 50题拍照合影留念
![](http://img.blog.csdn.net/20150816170217128?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
NUMBER BASE CONVERSION
Description
Write a program to convert numbers in one base to numbers in a second base. There are 62 different digits:
{ 0-9,A-Z,a-z }
HINT: If you make a sequence of base conversions using the output of one conversion as the input to the next, when you get back to the original base, you should get the original number.
Input
The first line of input contains a single positive integer. This is the number of lines that follow. Each of the following lines will have a (decimal) input base followed by a (decimal) output base followed by a number expressed
in the input base. Both the input base and the output base will be in the range from 2 to 62. That is (in decimal) A = 10, B = 11, ..., Z = 35, a = 36, b = 37, ..., z = 61 (0-9 have their usual meanings).
Output
The output of the program should consist of three lines of output for each base conversion performed. The first line should be the input base in decimal followed by a space then the input number (as given expressed in the input
base). The second output line should be the output base followed by a space then the input number (as expressed in the output base). The third output line is blank.
Sample Input
Sample Output
Source
Greater New York 2002
任意进制的转换
AC
NUMBER BASE CONVERSION
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4620 | Accepted: 2115 |
Write a program to convert numbers in one base to numbers in a second base. There are 62 different digits:
{ 0-9,A-Z,a-z }
HINT: If you make a sequence of base conversions using the output of one conversion as the input to the next, when you get back to the original base, you should get the original number.
Input
The first line of input contains a single positive integer. This is the number of lines that follow. Each of the following lines will have a (decimal) input base followed by a (decimal) output base followed by a number expressed
in the input base. Both the input base and the output base will be in the range from 2 to 62. That is (in decimal) A = 10, B = 11, ..., Z = 35, a = 36, b = 37, ..., z = 61 (0-9 have their usual meanings).
Output
The output of the program should consist of three lines of output for each base conversion performed. The first line should be the input base in decimal followed by a space then the input number (as given expressed in the input
base). The second output line should be the output base followed by a space then the input number (as expressed in the output base). The third output line is blank.
Sample Input
8 62 2 abcdefghiz 10 16 1234567890123456789012345678901234567890 16 35 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2 35 23 333YMHOUE8JPLT7OX6K9FYCQ8A 23 49 946B9AA02MI37E3D3MMJ4G7BL2F05 49 61 1VbDkSIMJL3JjRgAdlUfcaWj 61 5 dl9MDSWqwHjDnToKcsWE1S 5 10 42104444441001414401221302402201233340311104212022133030
Sample Output
62 abcdefghiz 2 11011100000100010111110010010110011111001001100011010010001 10 1234567890123456789012345678901234567890 16 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2 16 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2 35 333YMHOUE8JPLT7OX6K9FYCQ8A 35 333YMHOUE8JPLT7OX6K9FYCQ8A 23 946B9AA02MI37E3D3MMJ4G7BL2F05 23 946B9AA02MI37E3D3MMJ4G7BL2F05 49 1VbDkSIMJL3JjRgAdlUfcaWj 49 1VbDkSIMJL3JjRgAdlUfcaWj 61 dl9MDSWqwHjDnToKcsWE1S 61 dl9MDSWqwHjDnToKcsWE1S 5 42104444441001414401221302402201233340311104212022133030 5 42104444441001414401221302402201233340311104212022133030 10 1234567890123456789012345678901234567890
Source
Greater New York 2002
任意进制的转换
AC
#include <iostream> #include <cstring> #include <cstdio> #define maxn 999 int aa[maxn],bb[maxn]; char a[maxn],b[maxn]; using namespace std; int main(){ int loop,ibase,obase,i,count,len,j; cin>>loop; while(loop--){ scanf("%d %d %s",&ibase,&obase,a); len=strlen(a); for(i=len-1,j=0;i>=0;--i) aa[j++]=a[i]-(a[i]<='9'?48:a[i]<'a'?55:61); count=0; while(len>0){ j=len-1; while(j){ aa[j-1]+=aa[j]%obase*ibase; aa[j]/=obase; j--; } bb[count++]=aa[0]%obase; aa[0]/=obase; while(0<len&&!aa[len-1])len--; } ///printf("count=%d\n",count); for(b[count]='\0',i=count-1,j=0;i>=0;i--,j++) b[j]=bb[i]+(bb[i]<10?48:bb[i]<36?55:61); printf("%d %s\n%d %s\n\n",ibase,a,obase,b); } return 0; }
相关文章推荐
- opentaps初学习之安装(mysql)
- Linux解压乱码
- (medium)LeetCode .Implement Trie (Prefix Tree)
- linux下I/O缓冲
- 如何增加你的气场
- [J2EE基础]初识JSP和Servlet
- 音乐播放器
- mysql锁研究系列二(MySQL表级锁的锁模式)
- uva_658_It's not a Bug, it's a Feature!(最短路)
- 机房收费系统验收小结(一)
- UVA - 10014 - Simple calculations (经典的数学推导题!!)
- 多线程与并发 概论
- 数据结构:大堆
- NoSQL架构实践(二)——以NoSQL为主
- Java功底篇系列-03-一些位运算符你会如何理解?
- nginx手记-命令
- 3、观察者模式
- 古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子, 小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子对数为多少?
- 百度地图 经纬度和地理位置的转换
- Java虚拟机详解02----JVM内存结构