题目链接 http://www.patest.cn/contests/pat-a-practise/1027
这是一道水得不能再水的问题,大约就是将3个十位数转化成十三进制再格式化输出即可,需要注意的是,0应当输出“00”
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int a,b,c;
Scanner scanner=new Scanner(System.in);
a=scanner.nextInt();
b=scanner.nextInt();
c=scanner.nextInt();
System.out.print("#"+zhuan(a)+zhuan(b)+zhuan(c));
}
public static String zhuan(int a){
if(a==0) return "00";
HashMap<Integer, String> hashmap = new HashMap<Integer, String>();
for(int i=0;i<=9;i++)
hashmap.put(i, ""+i);
hashmap.put(10, "A");
hashmap.put(11, "B");
hashmap.put(12, "C");
ArrayList<Integer> arrayList=new ArrayList<Integer>();
while(a!=0){
arrayList.add(a%13);
a=a/13;
}
if(arrayList.size()==1)
arrayList.add(0);
String s="";
s=s+hashmap.get(arrayList.get(1));
s=s+hashmap.get(arrayList.get(0));
return s;
}
}