zoukankan      html  css  js  c++  java
  • poj1220

    高精度进制转换,java做

    View Code
    import java.io.*;
    import java.util.*;
    import java.math.*;

    public class Main {
    static int cal(char ch)
    {
    if (ch >= 'A' && ch <= 'Z')
    return (int)(ch - 'A' + 10);
    if (ch >= 'a' && ch <= 'z')
    return (int)(ch - 'a' + 36);
    return (int)(ch - '0');
    }
    static char get(long l)
    {
    if (l <= 9)
    return (char)(l + '0');
    if (l <= 35)
    return (char)(l - 10 + 'A');
    return (char)(l - 36 + 'a');
    }
    static public void main(String[] args) throws FileNotFoundException
    {
    Scanner cin = new Scanner(new BufferedInputStream(System.in));
    //Scanner cin = new Scanner(new FileInputStream("t.txt"));
    int t = cin.nextInt();
    while (t-- != 0)
    {
    int a = cin.nextInt();
    int b = cin.nextInt();
    String st = cin.next();
    BigInteger ans = new BigInteger("0");
    for (int i = 0; i < st.length(); i++)
    ans = ans.multiply(BigInteger.valueOf(a)).add(BigInteger.valueOf(cal(st.charAt(i))));
    //System.out.println(ans);
    String st1 = new String("");
    while (!ans.equals(BigInteger.valueOf(0)))
    {
    st1 = get(ans.mod(BigInteger.valueOf(b)).longValue()) + st1;
    ans = ans.divide(BigInteger.valueOf(b));
    }
    System.out.println(a + " " + st);
    if (st1.equals(""))
    System.out.println(b + " 0");
    else
    System.out.println(b + " " + st1);
    System.out.println();
    }
    }
    }

  • 相关阅读:
    操作系统原理
    Linux三剑客正则表达式
    Linux通配符知识深度实践详解
    Linux文件属性之时间戳及文件名知识详解
    Linux系统文件权限
    date:显示与设置系统时间
    正则表达式--三剑客简单应用
    Linux习题小结
    Linux系统文件属性知识
    Linux系统目录结构知识
  • 原文地址:https://www.cnblogs.com/rainydays/p/2183750.html
Copyright © 2011-2022 走看看