码迷,mamicode.com
首页 > 编程语言 > 详细

java水题集

时间:2019-05-03 09:24:31      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:pre   return   equal   int   click   net   import   show   input   

POJ - 1220 进制转换 

技术图片
 1 import java.io.*;
 2 import java.util.*;
 3 import java.math.*;
 4 
 5 public class Main {
 6     public static int GetNum(char c)
 7     {
 8         if (Character.isDigit(c))return c-‘0‘;
 9         if (Character.isUpperCase(c))return c-‘A‘+10;
10         if (Character.isLowerCase(c))return c-‘a‘+36;
11         return ‘0‘;
12     }
13     public static char GetChar(int x)
14     {
15         if (x<10)return (char)(x+‘0‘);
16         else if (x<=35) return (char)(x+‘A‘-10);
17         else return (char)(x+‘a‘-36);
18     }
19     public static void main(String[] args) 
20     {
21         Scanner cin= new Scanner(new BufferedInputStream(System.in));
22         int T=cin.nextInt();
23         while(T--!=0)
24         {
25             BigInteger base1=cin.nextBigInteger();
26             BigInteger base2=cin.nextBigInteger();
27             BigInteger n=BigInteger.ZERO;
28             String s=cin.next();
29             for(int i=0;i<s.length();i++)
30             {
31                 char c=s.charAt(i);
32                 n=n.multiply(base1).add(BigInteger.valueOf(GetNum(c)));
33             }
34             String ans=new String();
35             while(!n.equals(BigInteger.ZERO))
36             {
37                 ans=GetChar(n.mod(base2).intValue())+ans;
38                 n=n.divide(base2);
39             }
40             if(ans.length()==0) ans+=‘0‘;
41             System.out.println(base1+" "+s);
42             System.out.println(base2+" "+ans);
43             if (T>0)System.out.println();
44         }
45 
46     }
47 
48 }
View Code

 

java水题集

标签:pre   return   equal   int   click   net   import   show   input   

原文地址:https://www.cnblogs.com/mmmqqdd/p/10804083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!