POJ 1220

点击打开链接

高精度之间的转换,利用模板即可,可以看的资料里面

代码:


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char str[1000];;
int newBase , oldBase;
int start[1000] , ans[1000] , res[1000];
int getNum(char c){
    if(c >= '0' && c <= '9')
        return c-'0';
    if(c >= 'A' && c <= 'Z')
        return c-'A'+10;
    //if(c >= 'a' && c <= 'z')
        return c-'a'+36;
}
char getChar(int i){
    if(i >= 0 && i<= 9)
        return i+'0';
    if(i >= 10 && i<= 35)
        return i-10+'A';
    //if(i >= 36 && i <= 61)
        return i-36+'a';
}
void change(){
    int i;
    start[0] = strlen(str);
    for(i = 1 ; i <= start[0] ; i++)
        start[i] = getNum(str[i-1]);
}
void solve(){
    memset(res , 0 , sizeof(res));
    int y, i, j;
    while(start[0] >= 1){
        y = 0;
        i = 1;
        ans[0] = start[0];
        while(i <= start[0]){
            y = y*oldBase + start[i];
            ans[i++] = y / newBase;
            y %= newBase;
        }
        res[++res[0]] = y;
        i = 1;
        while(i <= ans[0] && ans[i] == 0)
            i++;
        memset(start , 0 , sizeof(start));
        for(j = i;j <= ans[0] ;j++)
            start[++start[0]] = ans[j];
        memset(ans , 0 ,sizeof(ans));
    }
}
void output(){
    int i;
    for(i = res[0] ; i >= 1 ; i--)
        printf("%c",getChar(res[i]));
    cout<<endl;
}   
int main(){
    int n , i;
    cin>>n;
    for(i = 1 ; i <= n ; i++){
        cin>>oldBase>>newBase;
        cin>>str;
        cout<<oldBase<<" "<<str<<endl;
        cout<<newBase<<" ";
        change();
        solve();
        output();
        if(i != n)
            cout<<endl;
    }
    return 0;
}      
    





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值