zoukankan      html  css  js  c++  java
  • 进制转化模板(十进制转其他进制)

    今天发现了一个好东西,进制转换

    #include<iostream>
    #include<cmath>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<algorithm>
    using namespace std;
    inline int rd()
    {
        int x=0,f=1;
        char ch=getchar();
        for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
        for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
        return x*f;
    }
    inline void write(int x)
    {
        if(x<0) putchar('-'),x=-x;
        if(x>9) write(x/10);
        putchar(x%10+'0');
        return ;
    }
    int s[100006];//存每个数位 
    int main()
    {
        int a,b;//把a转化为b进制数
        a=rd();
        b=rd();
        int pos=0; 
        while(a)
        {
            s[pos++]=a%b;//每一位不能超过b 
            a/=b;
        }
        while(pos--) printf("%d",s[pos]);//结果为反向 
        return 0;
    }
    蒟蒻总是更懂你✿✿ヽ(°▽°)ノ✿
  • 相关阅读:
    20201016---不做清单
    20201014--增删改查
    20201013--什么是真实的自己?
    多态
    继承
    关键字
    分类思想
    常用的linux命令
    九九乘法表
    稀疏数组
  • 原文地址:https://www.cnblogs.com/WWHHTT/p/9515931.html
Copyright © 2011-2022 走看看