POJ 1220

简介: 点击打开链接 高精度之间的转换,利用模板即可,可以看的资料里面 代码: #include #include #include using namespace std;char str[1000];;int newBase , ...

点击打开链接

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

代码:


#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;
}      
    


    


目录
相关文章
|
7月前
|
算法
Wormholes—POJ3259
Wormholes—POJ3259
|
算法框架/工具
POJ 2262 Goldbach's Conjecture
POJ 2262 Goldbach's Conjecture
139 0
poj 3620
题意:给出一个矩阵,其中有些格子干燥、有些潮湿。       如果一个潮湿的格子的相邻的四个方向有格子也是潮湿的,那么它们就可以构成更大       的湖泊,求最大的湖泊。       也就是求出最大的连在一块儿的潮湿的格子的数目。
574 0
poj 2299 求逆序数
http://poj.org/problem?id=2299 #include using namespace std; int aa[500010],bb[500010]; long long s=0; void merge(int l,int m,int r) { ...
802 0
poj-2551-ones
Description Given any integer 0
775 0
|
并行计算 网络架构
poj-1005-l tanink i need a houseboat
Description Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned ...
988 0
|
人工智能
POJ 1936 All in All
Description You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way.
792 0
|
机器学习/深度学习