zoukankan      html  css  js  c++  java
  • 进制转换模板

    package test3;
    import java.*;
    import java.util.*;
    public class Main112 {
        public static int value(char x){
            if(x>='0'&&x<='9')
                return x-'0';
            if(x>='a'&&x<='f')
                return x-'a'+10;
            if(x>='A' && x<='F') return x-'A'+10;
            return 0;
    
        }
         public static String jinzhi(String x,int q ,int m){
             int n=0;
             for(int i=0;i<x.length();i++){
                 n=q*n+value(x.charAt(i));
             }
             String t ="";
             for(;;){
                 if(n==0)break;
                 t=(n%m)+t;
                 n/=m;
             }
             return t;
         }
        public static void main(String[] args) {
             Scanner sc = new Scanner(System.in);
             String s = sc.nextLine();
             int q = sc.nextInt();
             int m = sc.nextInt();
             System.out.println(jinzhi(s,q,m));
        }
    
    }
  • 相关阅读:
    BZOJ 4010: [HNOI2015]菜肴制作( 贪心 )
    bzoj 1084
    bzoj 2763
    bzoj 1003
    bzoj 1858
    codevs 1296
    cf 438D
    vijos 1083
    codevs 3303
    bzoj 1296
  • 原文地址:https://www.cnblogs.com/ls-pankong/p/10468372.html
Copyright © 2011-2022 走看看