题解 | #进制转换#

进制转换

https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str=in.nextLine().substring(2);
        int total=0;
        Map<Character,Integer> hs=new HashMap<>();
        hs.put('0',0);
hs.put('1',1);
hs.put('2',2);
hs.put('3',3);
hs.put('4',4);
hs.put('5',5);
hs.put('6',6);
hs.put('7',7);
hs.put('8',8);
hs.put('9',9);
hs.put('A',10);
hs.put('B',11);
hs.put('C',12);
hs.put('D',13);
hs.put('E',14);
hs.put('F',15);

        for(int i=str.length()-1,j=0;i>=0;i--,j++){
            total+=hs.get(str.charAt(i))*(int)Math.pow(16,j);
        }
        System.out.println(total);
    }

    
}

全部评论

相关推荐

风中翠竹:真的真的真的没有kpi。。。面试官是没有任何kpi的,捞是真的想试试看这个行不行,碰碰运气,或者是面试官比较闲现在,没事捞个人看看。kpi算HR那边,但是只有你入职了,kpi才作数,面试是没有的。
双非有机会进大厂吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务