题意

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.

分析

参照某神犇的代码。

此代码异常简洁,本来我想先转十进制在转其他的,没想到可以直接做。

代码

POJ最近炸了,只好在openjudge百练上交了。

#include<bits/stdc++.h>
#define rg register
#define il inline
#define co const
template<class T>il T read(){
    rg T data=0,w=1;
    rg char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-') w=-1;
        ch=getchar();
    }
    while(isdigit(ch))
        data=data*10+ch-'0',ch=getchar();
    return data*w;
}
template<class T>il T read(rg T&x){
    return x=read<T>();
}
typedef long long ll;

co int N=1000;
int t[N],A[N];
char str1[N],str2[N];
int n,m;
void solve(){
    int len=strlen(str1);
    for(int i=len;i>=0;--i)
        t[len-1-i]=str1[i]-(str1[i]<58?48:str1[i]<97?55:61);
    int k;
    for(k=0;len;){
        for(int i=len;i>=1;--i){
            t[i-1]+=t[i]%m*n;
            t[i]/=m;
        }
        A[k++]=t[0]%m;
        t[0]/=m;
        while(len>0&&!t[len-1]) --len;
    }
    str2[k]=0;
    for(int i=0;i<k;++i)
        str2[k-1-i]=A[i]+(A[i]<10?48:A[i]<36?55:61);
}
int main(){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    int kase=read<int>();
    while(kase--){
        read(n),read(m);
        scanf("%s",str1);
        solve();
        printf("%d %s\n%d %s\n\n",n,str1,m,str2);
    }
    return 0;
}

POJ1220 Number Base Conversion的更多相关文章

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

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

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

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

  3. poj 1220 NUMBER BASE CONVERSION

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

  4. NUMBER BASE CONVERSION(进制转换)

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

  5. SZU:J38 Number Base Conversion

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

  6. (高精度运算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_ ...

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

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

  8. Base Conversion In PHP and javascript

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

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

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

随机推荐

  1. key中断

    1 中断,很短的时间过去,然后回来.2 信号,软中断,而中断属于硬中断.3 实时内核,和分时内核.4 同步,预先知道发生,异步,预先不知道要发生,中断属于异步.5 arm一次执行一个中断.6 irq中 ...

  2. hdu3706单调队列

    很基础的单调队列 #include<map> #include<set> #include<cmath> #include<queue> #includ ...

  3. 原生javascript-Tab选项卡-面向对象

    分析个人用原生JS获取类名元素的代码: getByClassName:function(className,parent){ var elem = [], node = parent != undef ...

  4. confluence wiki 破解安装操作流程

    准备postgres数据库安装 步骤1:命令: docker pull postgres 步骤2:安装: docker run --name postgresdb -p 5432:5432 -e PO ...

  5. Hugepages,hugetlb_shm_group与ORA-27125

    Hugepages,hugetlb_shm_group与ORA-27125 转载:http://www.eygle.com/archives/2011/12/hugepageshugetl.html ...

  6. js字符串操作方法

    1.字符方法: str.charAt(): 可以访问字符串中特定的字符,可以接受0至字符串长度-1的数字作为参数,返回该位置下的字符,如果参数超出该范围,返回空字符串,如果没有参数,返回位置为0的字符 ...

  7. bzoj1269

    题解: splay维护 只不过变成了字符串 代码: #include<bits/stdc++.h> using namespace std; +,BS= + ,BN= + ; ,head, ...

  8. LeetCode OJ:Gas Station(加油站问题)

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  9. The program environment for cypress cy8ckit-002

    customer use cypress ic to make sure the  wireless products, we are prepare to establish the environ ...

  10. wireshark的一些快捷键

    恢复原来的大小   ‘crtl’+‘=’  即按住crtl建和=键(backspace左边那个键) 缩小 ‘crtl’+‘-’ 即按住crtl建和-键(backspace左边第二个键) 放大 ‘crt ...