NUMBER BASE CONVERSION
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 5976   Accepted: 2738

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
 #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
//#include<vector>
//#include<queue>
//#include<set>
#define INF 0x3f3f3f3f
#define N 100005
#define re register
#define Ii inline int
#define Il inline long long
#define Iv inline void
#define Ib inline bool
#define Id inline double
#define ll long long
#define Fill(a,b) memset(a,b,sizeof(a))
#define R(a,b,c) for(register int a=b;a<=c;++a)
#define nR(a,b,c) for(register int a=b;a>=c;--a)
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
#define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
#define D_e(x) printf("\n&__ %d __&\n",x)
#define D_e_Line printf("-----------------\n")
#define D_e_Matrix for(re int i=1;i<=n;++i){for(re int j=1;j<=m;++j)printf("%d ",g[i][j]);putchar('\n');}
using namespace std;
//The Code Below Is Bingoyes's Function Forest.
Ii read(){
int s=,f=;char c;
for(c=getchar();c>''||c<'';c=getchar())if(c=='-')f=-;
while(c>=''&&c<='')s=s*+(c^''),c=getchar();
return s*f;
}
Iv print(int x){
if(x<)putchar('-'),x=-x;
if(x>)print(x/);
putchar(x%^'');
}
/*
Iv Floyd(){
R(k,1,n)
R(i,1,n)
if(i!=k&&dis[i][k]!=INF)
R(j,1,n)
if(j!=k&&j!=i&&dis[k][j]!=INF)
Cmin(dis[i][j],dis[i][k]+dis[k][j]);
}
Iv Dijkstra(int st){
priority_queue<int>q;
R(i,1,n)dis[i]=INF;
dis[st]=0,q.push((nod){st,0});
while(!q.empty()){
int u=q.top().x,w=q.top().w;q.pop();
if(w!=dis[u])continue;
for(re int i=head[u];i;i=e[i].nxt){
int v=e[i].pre;
if(dis[v]>dis[u]+e[i].w)
dis[v]=dis[u]+e[i].w,q.push((nod){v,dis[v]});
}
}
}
Iv Count_Sort(int arr[]){
int k=0;
R(i,1,n)
++tot[arr[i]],Cmax(mx,a[i]);
R(j,0,mx)
while(tot[j])
arr[++k]=j,--tot[j];
}
Iv Merge_Sort(int arr[],int left,int right,int &sum){
if(left>=right)return;
int mid=left+right>>1;
Merge_Sort(arr,left,mid,sum),Merge_Sort(arr,mid+1,right,sum);
int i=left,j=mid+1,k=left;
while(i<=mid&&j<=right)
(arr[i]<=arr[j])?
tmp[k++]=arr[i++]:
(tmp[k++]=arr[j++],sum+=mid-i+1);//Sum Is Used To Count The Reverse Alignment
while(i<=mid)tmp[k++]=arr[i++];
while(j<=right)tmp[k++]=arr[j++];
R(i,left,right)arr[i]=tmp[i];
}
Iv Bucket_Sort(int a[],int left,int right){
int mx=0;
R(i,left,right)
Cmax(mx,a[i]),++tot[a[i]];
++mx;
while(mx--)
while(tot[mx]--)
a[right--]=mx;
}
*/
char number[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",str[N],str_new[N];
int main(){
int T=read();
while(T--){
int a=read(),b=read();
scanf("%s",str),
printf("%d %s\n",a,str);
int len=strlen(str),flag=,digit=;
while(flag){
flag=;
int res=;
R(i,,len-){
int num;
if(str[i]>=''&&str[i]<='')num=str[i]^'';
if(str[i]>='A'&&str[i]<='Z')num=str[i]-'A'+;
if(str[i]>='a'&&str[i]<='z')num=str[i]-'a'+;
num+=res*a,res=num%b,str[i]=number[num/b];
if(str[i]!='')
flag=;
}
str_new[++digit]=number[res];
}
printf("%d ", b);
nR(i,digit,)
printf("%c",str_new[i]);
printf("\n\n");
}
return ;
}
/*
Note:
There is always a truth: High precision is the descendants of Satan.
*/

poj 1220 NUMBER BASE CONVERSION的更多相关文章

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

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

  2. POJ 1220 NUMBER BASE CONVERSION(较复杂的进制转换)

    题目链接 题意 : 给你一个a进制的数串s,让你转化成b进制的输出. A = 10, B = 11, ..., Z = 35, a = 36, b = 37, ..., z = 61,0到9还是原来的 ...

  3. (高精度运算4.7.26)POJ 1220 NUMBER BASE CONVERSION(高精度数的任意进制的转换——方法:ba1----->10进制----->ba2)

    package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class POJ_1220_ ...

  4. NUMBER BASE CONVERSION(进制转换)

    Description Write a program to convert numbers in one base to numbers in a second base. There are 62 ...

  5. POJ1220 Number Base Conversion

    题意 Write a program to convert numbers in one base to numbers in a second base. There are 62 differen ...

  6. SZU:J38 Number Base Conversion

    Judge Info Memory Limit: 32768KB Case Time Limit: 1000MS Time Limit: 1000MS Judger: Number Only Judg ...

  7. [POJ1220]NUMBER BASE CONVERSION (高精,进制转换)

    题意 任意进制之间的高进的转换 思路 相模倒排,高精处理 代码 我太弱了,下面附一个讨论里发的maigo思路的代码 ],A[]; ],d[]; main(){ for(scanf("%d&q ...

  8. Base Conversion In PHP and javascript

    http://www.exploringbinary.com/base-conversion-in-php-using-built-in-functions/ http://www.binarycon ...

  9. Poj 1019 Number Sequence( 数据分析和操作)

    一.题目大意 有这样一个序列包含S1,S2,S3...SK,每一个Si包括整数1到 i.求在这个序列中给定的整数n为下标的数. 例如,前80位为1121231234123451234561234567 ...

随机推荐

  1. MySql 之 FIND_IN_SET 和IN

    CREATE TABLE `test` (   `id` int(8) NOT NULL auto_increment,   `name` varchar(255) NOT NULL,   `list ...

  2. 20-取石子动态规则(hdu2516 斐波那契博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=2516 取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memor ...

  3. javac老提示无效的标记

    加上-cp libs/*后,就开始提示无效的标记,搞了半天,似乎是shell展开的问题,估计是把后面的jar文件当源文件了? 加上引号就行了-cp "libs/*",不让shell ...

  4. 一步一步带你构建第一个 Laravel 项目

    参考链接:https://laravel-news.com/your-first-laravel-application 简介 按照以下的步骤,你会创建一个简易的链接分享网站. 安装 Laravel ...

  5. linux学习1----初涉linux

    linux因其稳定高效的特点,受到很多开发者的青睐,因此将其作为服务器的操作系统. 作为一名开发者,程序员,掌握了一定的linux知识和技巧,程序的开发部署和运行也有不小的帮助. linux由于其开源 ...

  6. 第16章-使用Spring MVC创建REST API

    1 了解REST 1.1 REST的基础知识 REST与RPC几乎没有任何关系.RPC是面向服务的,并关注于行为和动作:而REST是面向资源的,强调描述应用程序的事物和名词. 为了理解REST是什么, ...

  7. phpmyadmin安全预防

    头疼的安全 之前服务器总是本人黑,千疮百孔,只能一步步的去做一些安全防范,如何防范自然先从如何渗透开始. 文章及建议 前段时间看到了个phpmyadmin提权的教程,很多人都说现在那里还有root帐号 ...

  8. 编写高质量代码改善C#程序的157个建议——建议36:使用FCL中的委托声明

    建议36:使用FCL中的委托声明 FCL中存在3类这样的委托声明,它们分别是:Action.Func.Predicate.尤其是在它们的泛型版本出来以后,已经能够满足我们在实际编码过程中的大部分需求. ...

  9. 解决iReport打不开的一种方法

    解决iReport打不开的一种方法 iReport版本:iReport-5.6.0-windows-installer.exe 系统:Win7 64位 JDK:1.7 在公司电脑安装没问题,能打开,但 ...

  10. Android 动态改变图片的颜色值

    public void onViewClicked(View view) { switch (view.getId()) { case R.id.bt1: img1.setColorFilter(ge ...