题解 | #进制转换#

进制转换

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

import java.util.Scanner;
import java.lang.Math;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.next();
            System.out.print(getChange(str));
        }
        sc.close();
    }
    private static int getChange(String s){
        int n = 0;
        for(int i=0;i<s.length()-2;i++){
            int num = 0;
            char c = s.toUpperCase().charAt(i+2);
            
            if(Character.isDigit(c)){
                num = c - '0';
            }else{
                 num = c - 'A' + 10;
            }
            n += num * Math.pow(16,s.length()-i-3);
        }

        return n; 
    

    }
}
全部评论

相关推荐

zzzilik:没事的,才刚刚开始,后面会捞的,这个三天没人发起面试自动结束,但是面试官还是能看到简历,四月份主战场会慢慢捞
点赞 评论 收藏
分享
钱嘛数字而已:拖拉机被发明出来之后,就不需要农民了吗?农民还是需要的,但不需要这么多了,另外对农民的要求也变高了,需要会开拖拉机。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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