博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
大数进制转换 poj1220
阅读量:7091 次
发布时间:2019-06-28

本文共 2488 字,大约阅读时间需要 8 分钟。

普通的做法,大数除小数。

复杂度o( log(n)*log(n) ),其实就是位数的平方。

NUMBER BASE CONVERSION
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4913   Accepted: 2246

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

862 2 abcdefghiz10 16 123456789012345678901234567890123456789016 35 3A0C92075C0DBF3B8ACBC5F96CE3F0AD235 23 333YMHOUE8JPLT7OX6K9FYCQ8A23 49 946B9AA02MI37E3D3MMJ4G7BL2F0549 61 1VbDkSIMJL3JjRgAdlUfcaWj61 5 dl9MDSWqwHjDnToKcsWE1S5 10 42104444441001414401221302402201233340311104212022133030

Sample Output

62 abcdefghiz2 1101110000010001011111001001011001111100100110001101001000110 123456789012345678901234567890123456789016 3A0C92075C0DBF3B8ACBC5F96CE3F0AD216 3A0C92075C0DBF3B8ACBC5F96CE3F0AD235 333YMHOUE8JPLT7OX6K9FYCQ8A
#include 
#include
#include
#include
#include
#include
using namespace std;char str[10100];int num[10100];int ans[10100];int chg(char c){ if( c>='0'&&c<='9' ) return c-'0'; if( c>='A'&&c<='Z' ) return c-'A'+10; if( c>='a'&&c<='z' ) return c-'a'+36; return -1;}char unchg(int x){ if(x>=0&&x<=9) return x+'0'; if(x>=10&&x<=35) return 'A'+x-10; else return 'a'+x-36;}int main(){ int T; cin>>T; while(T--) { int from,to; scanf("%d%d",&from,&to); scanf("%s",str); int len=strlen(str); for(int i=0;i
=0;i--) { printf("%c",unchg(ans[i])); } printf("\n\n"); } return 0;}

 

转载地址:http://wjiql.baihongyu.com/

你可能感兴趣的文章
内存堆与栈的区别
查看>>
NHibernate初学者指南(12):日志
查看>>
30 个设计新颖的网站风格展示
查看>>
概念——统一资源定位符(Uniform / Universal Resource Locator,URL)
查看>>
Apache HttpComponents 获取Cookie
查看>>
彻底理解jdbc为什么用反射创建驱动程序对象
查看>>
Oracle内存管理(之五)
查看>>
[nio]dawn的基本概念
查看>>
【数据库摘要】6_Sql_Inner_Join
查看>>
交叉熵代价函数(损失函数)及其求导推导
查看>>
Android UI开源框架
查看>>
Java 构造时成员初始化的陷阱
查看>>
CentOS7.1 Liberty云平台之环境准备(2)
查看>>
js正则表达式test方法、exec方法与字符串search方法区别
查看>>
4.终端
查看>>
优秀的 Spring Cloud 开源软件
查看>>
mysql数据库的简单语句的介绍(1)
查看>>
HDU 2829 Lawrence (斜率DP)
查看>>
visual studio 2012 update3
查看>>
特征值和特征向量的几何意义、计算及其性质
查看>>