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

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

#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int n,i,x,y,l,k,t[],b[];
char s[],ans[];//由于超过十进制的数含有字母,因此用字符串数组储存
for (scanf("%d",&n);n--;)
{
scanf("%d%d%s",&x,&y,s);
for (i=k=strlen(s);<i--;)
t[k--i]=s[i]-(s[i]<?:s[i]<?:);//ascall码48到57为字符0到一,97到122对应小写字母a到b,将字符转变成相应的十进制数存入数组t中。
for (l=;k;)
{
for (i=k;<i--;) //这一坨for循环我实在搞不懂啥意思
{
t[i-]+=t[i]%y*x;
t[i]/=y;//貌似是使除t[0]以外的变为y进制,避免了重复的运算
}
b[l++]=t[]%y;//由于t[0]是最低位,相当于将t[0]作为一个独立的单位进行处理。
t[]/=y;
for (;<k&&!t[k-];k--);//当t最高位为0时,缩短t的长度。
}
for (ans[l]=i=;i<l;i++)
ans[l--i]=b[i]+(b[i]<?:b[i]<?:);
printf("%d %s\n%d %s\n\n",x,s,y,ans);
}
return ;
 
 

NUMBER BASE CONVERSION(进制转换)的更多相关文章

  1. $Poj1220/AcWing124\ Number\ Base\ Convertion$ 进制转换+高精除

    $Poj$   $AcWing$ $Description$ $Sol$ 进制转化+高精度除法 $over$ $Code$ #include<bits/stdc++.h> #define ...

  2. HDU 4937 Lucky Number (数学,进制转换)

    题目 参考自博客:http://blog.csdn.net/a601025382s/article/details/38517783 //string &replace(iterator fi ...

  3. poj 1220 NUMBER BASE CONVERSION(短除法进制转换)

    题目连接:1220 NUMBER BASE CONVERSION 题目大意:给出两个进制oldBase 和newBase, 以及以oldBase进制存在的数.要求将这个oldBase进制的数转换成ne ...

  4. 11 JavaScript Number原始值&对象&科学记数法&范围&进制转换&溢出Infinity&NaN

    JavaScript Number对象 是经过封装的能处理数字值的对象 由Number()构造器创建 只有一种数字类型 可以使用也可以不使用小数点书写数字 JavaScript原始值与对象: 在Jav ...

  5. Python内置函数进制转换的用法

    使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x)Convert an integer numb ...

  6. POJ1220(大数进制转换)

    NUMBER BASE CONVERSION Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4652   Accepted: ...

  7. Python 内置函数进制转换的用法(十进制转二进制、八进制、十六进制)

    使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x)Convert an integer numb ...

  8. python中进制转换

    使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x)Convert an integer numb ...

  9. python 小兵内置函数进制转换

    Python内置函数进制转换的用法 使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x)Conve ...

  10. Java:进制转换

    进制转换是常常需要的一种数据处理,在java中的一些类中封装了具有转换功能的方法,这个不做介绍.其实,进制之间的转化是通过先位异或&,再位移动>>>的方式实现的. 例如,对于 ...

随机推荐

  1. “/”应用程序中的服务器错误。 / c:\windows\temp目录权限设置

    说明: 1 对该目录的权限是ASP.net生成编译运行的临时文件需要,ASP不需要这个目录是因为ASP的脚本代码是解释执行. 2 Windows2003默认的设置是可以正常运行ASP.net的,造成问 ...

  2. 黑马程序员_Java基础组成

    Java语言基础组成 2.1关键字 main不是关键字,但被JVM所识别的名称. 关键字的定义和特点 定义:被Java语言赋予了特殊含义的单词. 特点:关键字中所有字母都为小写. 用于定义数据类型的关 ...

  3. HDOJ(HDU) 1994 利息计算(简单题目)

    Problem Description 为自行解决学费,chx勤工俭学收入10000元以1年定期存入银行,年利率为3.7% .利率 按年计算,表示100元存1年的利息为3.7元.实际上有时提前有时推迟 ...

  4. tcp/ip状态图

    开启一个连接需要三次握手,终止一个tcp连接需要4次握手,对应的客户端和服务器连接状态也随之而改变. 1.服务器出现大量的CLOSE_WAIT? 通常,CLOSE_WAIT 状态在服务器停留时间很短, ...

  5. EMV/PBOC解析(三) TLV格式解析(C#)

    1.什么是TLV格式? TLV即Tag-Length-Value,常在IC卡与POS终端设备中通过这样的一个应用通信协议进行数据交换. 金融系统中的TLV是BER-TLV编码的一个特例编码规范,而BE ...

  6. Android项目实战--手机卫士18--读取用户的短信内容以及短信备份

    我们今天要说的就是我们手机卫士里面的高级工具里面的短信备份功能啦,其实这个软件备份的功能也很简单,就是把用户的短信读出来,然后写到一个xml或者数据库里面, 但我们这里的是读取到xml里面的. 首先我 ...

  7. Ubuntu启动时直接进入命令行模式

    直接粘命令吧 sudo vim /etc/init/lightdm.conf 注释掉下面的内容 start on ((filesystem and runlevel [!06] and started ...

  8. ifconfig命令详解

    linux下网上命名规律:eth0,eth1.第一块以太网卡,第二块.lo为环回接口,它的IP地址固定为127.0.0.1,掩码8位.它代表你的机器本身. 1.ifconfig是查看网卡的信息 eth ...

  9. html移动端开发注意事项

    meta <meta charset="utf8"> <meta name="viewport" content="width=de ...

  10. 2015 UESTC Winter Training #4【Regionals 2008 :: Asia - Tehran】

    2015 UESTC Winter Training #4 Regionals 2008 :: Asia - Tehran 比赛开始时电脑死活也连不上WIFI,导致花了近1个小时才解决_(:зゝ∠)_ ...