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. 值得收藏的Javascript代码

    1  Javascript数组转换为CSV格式 首先考虑如下的应用场景,有一个Javscript的字符型(或者数值型)数组,现在需要转换为以逗号分割的CSV格式文件.则我们可以使用如下的小技巧,代码如 ...

  2. 配置Windows 2008 R2 防火墙允许远程访问SQL Server 2008 R2 更改端口 连接字符串 IP+逗号+端口号

      1.先修改 sql server 2008R2的端口号吧,1433经常成为别人入侵的端口,在sql server 配置管理器 -->sql server 网络配置-->MSSQLSER ...

  3. AWK中几个变量

    学习AWK语言 https://awk.readthedocs.org/en/latest/chapter-one.html http://www.ibm.com/developerworks/cn/ ...

  4. apt-mirror

    对于centos来说,搭建一个本地源,相对来说,还是比较简单的.对于ubuntu来说,就复杂很多, 估计也和我不熟悉有关. http://unixrob.blogspot.com/2012/05/cr ...

  5. UIStackView相关

    从iOS9开始,苹果提供了UIStackView来帮助我们做布局,这玩意儿类似于安卓的线性布局.因为在使用过程中会遇到一些坑,所以写出来供遇到同样问题的人参考.我在这里提供xib和纯代码两种方式创建使 ...

  6. 在sql语句中使用plsql变量

    示例代码如下: create or replace type ua_id_table is table of number; declare v_tab ua_id_table;begin v_tab ...

  7. Struts2框架具体解释

    在Struts2的Model-View-Controller模式实现下面五个核心组件: 动作-Actions 拦截器-Interceptors 值栈/OGNL 结果/结果类型 视图技术 Struts ...

  8. 【Android】无限滚动的HorizontalScrollView

    这是一个很简单的功能,作为新手,做一下笔记.也给其它有需要的人提供一个参考. 首先HorizontalScrollView都知道用途了.它可以实现类似“桌面程序”左右切换页的效果.一般情况下里面的页数 ...

  9. MySQL(14):Select-limit(限制获得的记录数量)

    1. limit 限制获得记录的数量 2.limit 语法: (1) limit  offset, row_count: offset偏移量,从0开始. row_count总记录数. 分析: 案例演示 ...

  10. 大数据笔记05:大数据之Hadoop的HDFS(数据管理策略)

            HDFS中数据管理与容错 1.数据块的放置       每个数据块3个副本,就像上面的数据库A一样,这是因为数据在传输过程中任何一个节点都有可能出现故障(没有办法,廉价机器就是这样的) ...