POJ1220 steals the code and uses java and poj1220java.

Source: Internet
Author: User

POJ1220 steals the code and uses java and poj1220java.

The meaning of the question is hexadecimal conversion. Java's big data classes are like cheating.

import java.math.BigInteger;import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        int n=in.nextInt();        while(n!=0){            int a=in.nextInt();            int b=in.nextInt();            String c=in.next();            BigInteger sum=BigInteger.ZERO;            for(int i=0;i<c.length();i++){                sum=sum.multiply(BigInteger.valueOf(a)).add(BigInteger.valueOf(getnum(c.charAt(i))));            }            String cc="";            while(!sum.equals(BigInteger.ZERO)){                cc=setchar(sum.mod(BigInteger.valueOf(b)).intValue())+cc;                sum=sum.divide(BigInteger.valueOf(b));            }            if(cc.equals("")) cc="0";            System.out.println(a+" "+c);            System.out.println(b+" "+cc);            System.out.println();            n--;        }    }    static int getnum(char m){        if(m>='0' && m<='9') return m-'0';        else if(m>='A' && m<='Z') return m-'A'+10;        else return m-'a'+36;    }    static char setchar(int n){        if(n<=9) return (char)(n+'0');        else if(n<=35) return (char)(n-10+'A');        else return (char)(n-36+'a');    }}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.