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


    


目录
相关文章
POJ 1067 取石子游戏
取石子游戏 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 40917   Accepted: 13826 Description 有两堆石子,数量任意,可以不同。
1090 0
poj 3664
http://poj.org/problem?id=3664 进行两轮选举,第一轮选前n进入第二轮,第二轮选最高   #include #include using namespace std; struct vote { int a,b; int c; ...
709 0
POJ 1804
题目:http://poj.org/problem?id=1804 大意:给你一串数字,排序。求出最少的交换次数  \ 我用归并做的 #include #include using namespace std; int aa[500010],bb[500010]; long lon...
674 0
poj-3094-quicksum
http://poj.org/problem?id=3094 很简单 #include #include using namespace std; int main() { string a; int sum=0; while(getline(cin...
553 0
POJ-1003-hangover
Description How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length.
740 0
poj-1008-玛雅历
Description 上周末,M.A. Ya教授对古老的玛雅有了一个重大发现。从一个古老的节绳(玛雅人用于记事的工具)中,教授发现玛雅人使用了一个一年有365天的叫做Haab的历法。这个Haab历法拥有19个月,在开始的18个月,一个月有20天,月份的名字分别是pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu。
855 0
|
机器学习/深度学习