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. 【项目运行异常】BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

    java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking ...

  2. java就业指南 zookeeper分布式系统 zookeeper实现分布式锁 有用

    目前几乎很多大型网站及应用都是分布式部署的,分布式场景中的数据一致性问题一直是一个比较重要的话题.分布式的CAP理论告诉我们“任何一个 分布式系统都无法同时满足一致性(Consistency).可用性 ...

  3. Linux设置串口波特率等参数

    转自 http://blog.csdn.net/zoomdy/article/details/50921336 mingdu.zheng at gmail dot com stty查看串口参数 stt ...

  4. 6.AND & OR 运算符

    AND 和 OR 运算符用于基于一个以上的条件对记录进行过滤 AND 和 OR 运算符 AND 和 OR 可在 WHERE 子语句中把两个或多个条件结合起来. 如果第一个条件和第二个条件都成立,则 A ...

  5. 特征选择Boruta

    A good feature subset is one that: contains features highly correlated with (predictive of) the clas ...

  6. Robot Framework - 基础关键字 BuiltIn 库(一)

    今天给大家分享的是Robot Framework 机器人框架中 BuiltIn 基础库的使用...BuiltIn 库里面提供了很多基础方法助力于我们在自动化测试领域中做的更好!——本系列教程是教会大家 ...

  7. unity 大游戏使用什么框架

    关于Unity的架构有如下几种常用的方式.1.EmptyGO在Hierarchy上创建一个空的GameObject,然后挂上所有与GameObject无关的逻辑控制的脚本.使用GameObject.F ...

  8. Castle Windsor

    让我们从Web API的集成点开始,它们是IDependencyResolver和IDependencyScope接口.IDependencyResolver和其他接口的名称可能与MVC中的接口相同, ...

  9. ORA-14402:更新分区关键字列将导致分区更改

    开启行迁移就好了:alter table TABLE_NAME enable row movement; 注意:表分区的时候要确定分区字段是否会UPDATE,如果会的话一定要开启行迁移,否则就会报这个 ...

  10. luoguP3648 [APIO2014]序列分割

    https://www.luogu.org/problemnew/show/P3648 同bzoj3675 这题斜率优化+滚动数组就可以了qwq 因为我是在飞机上瞎bb的式子,所以可能会和别的题解的式 ...