题解 | #进制转换#

进制转换

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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // Life is short, i love JAVA.
        // System.out.println(Integer.valueOf(in.next().substring(2), 16));
        String str = in.nextLine();
        int result = 0, i = 2, len = str.length();
        while (i < len) {
            char c = str.charAt(i++);
            int ch;
            if (c >= '0' && c <= '9') {
                ch = c - '0';
            } else if (c >= 'a' && c <= 'z') {
                ch = c - 'a' + 10;
            } else {
                ch = c - 'A' + 10;
            }
            result *= 16;
            result += ch;
        }
        System.out.println(result);
    }
}

#华为笔试#
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 11:20
点赞 评论 收藏
分享
强大的马里奥:不太可能,我校计算机硕士就业率99%
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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