zoukankan      html  css  js  c++  java
  • poj1220:高精度进制转换模板题

    今天撸3708  一直奇怪的re 就先放下了,写这个题的过程中学习了一个高精度进制转换,用这个模板写了1220

    记录一下:

    #include <iostream>
    #include <stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<string>
    #include<ctype.h>
    using namespace std;
    #define MAXN 10000
    char s[10000];
    int start[10000];
    int res[10000];
    int ans[10000];
    int getnum(char c)
    {
        if(c>='a')
            return c-'a'+36;
        if(c>='A')
            return c-'A'+10;
        return c-'0';
    }
    char getchar(int n)
    {
        if(n>=36)
            return 'a'+n-36;
        if(n>=10)
            return 'A'+n-10;
        return '0'+n;
    }
    void trans(char* str,int base0,int base1)
    {
        memset(res,0,sizeof(res));
        int y,i,j;
        start[0]=strlen(str);
        for(i=1;i<=start[0];i++)
        {
            start[i]=getnum(str[i-1]);
        }
        while(start[0]>=1)
        {
            y=0; //余数
            ans[0]=start[0];
            for(i=1;i<=start[0];i++)
            {
                y=y*base0+start[i];
                ans[i]=y/base1;
                y%=base1;
            }
            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));
        }
        return;
    }
    void output()
    {
        for(int i=res[0];i;i--)
            printf("%c",getchar(res[i]));
        printf("
    ");
    }
    int main()
    {
        #ifndef ONLINE_JUDGE
            freopen("shu.txt","r",stdin);
        #endif
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int x,y;
            scanf("%d%d%s",&x,&y,s);
            trans(s,x,y);
            printf("%d %s
    ",x,s);
            printf("%d ",y);
            output();
            printf("
    ");
        }
    
    
        return 0;
    }
  • 相关阅读:
    HTTP协议基础
    MySQL必知必会总结(二)
    MySQL必知必会总结(一)
    微信小程序开发总结
    从零开始搭建物联网平台(8):邮箱通知服务
    使用CDN优化首页加载速度
    Django+Vue前后端分离项目的部署
    Docker命令
    Django中间件执行流程和CSRF验证
    golang 快速排序及二分查找
  • 原文地址:https://www.cnblogs.com/oneshot/p/3989150.html
Copyright © 2011-2022 走看看