题解 | #进制转换#

进制转换

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);
    }

    
}

全部评论

相关推荐

Twilight_m...:还是不够贴近现实,中关村那块60平房子200万怎么可能拿的下来,交个首付还差不多
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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