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. HBase Client API使用(二)---查询及过滤器

    相关知识 创建表插入数据删除等见:http://www.cnblogs.com/wishyouhappy/p/3735077.html HBase API简介见:http://www.cnblogs. ...

  2. 怎样把.git版本控制文件夹放在项目目录下

    在上传本地代码到本地git库时,.git的存放目录不能放到项目根目录下(报错). 可以先把.git仓库选择其他保存路径,然后再copy到项目根目录下.

  3. jenkins 设置权限后管理员登陆提示:Access Denied admin没有Overall/Read权限

    jenkins 设置权限后,管理员登陆提示:Access Denied  admin没有Overall/Read权限 处理办法: window下编辑 xml 配置文件: %userprofile%\. ...

  4. java—— 编译与运行

    内容:使用javac 指定编译多个目录下java文件 链接:http://zhidao.baidu.com/link?url=W5ZERu8_ouGD-L_JH0vqqawhJNitsGbonQAAT ...

  5. xml--通过DOM解析XML

    此文章通过3个例子表示DOM方式解析XML的用法. 通过DOM解析XML必须要写的3行代码. step 1: 获得dom解析器工厂(工作的作用是用于创建具体的解析器) step 2:获得具体的dom解 ...

  6. Atitit.Gui控件and面板----数据库区-mssql 2008 权限 配置 报表查看成员

    Atitit.Gui控件and面板----数据库区-mssql 2008 权限 配置 报表查看成员 1. 配置server连接权限 1 2. 配置数据库权限 1 3. 设置表格/视图安全性 2 1.  ...

  7. POJ2230 Watchcow【欧拉回路】

    Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6172Accepted: 2663 Special Judge ...

  8. Android NumberPicker默认外观的修改

    NumberPicker是Android3.0之后引入的一个控件,在以后的TimePicker和DatePicker时间控件里边都有引用,NumberPicker本身并没有提供接口给开发者修改其默认外 ...

  9. [转] 看懂UML类图和时序图

    PS: 组合关系:实心,一个类A属于另一个类,或多个类,但是类A不能单独存在去使用,A一般是一种抽象的东西 聚合关系:空心,一个类A可以单独存在使用 不论组合聚合,A的方法都会被直接调用. 看懂UML ...

  10. CentOS 7 修改hostname

    centOS 7 里面修改hostname的方式有所改变,修改/etc/hosts和/etc/sysconfig/network两个文件已经不能生效.使用的新命令是 : hostnamectl set ...