题解 | 十六进制转十进制

十六进制转十进制

https://www.nowcoder.com/practice/33e148570d5c4e728116e2f861638c9c

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
    var a string = "ABCDEF"
    var sum int = 0
    var temp int = 0
    temps := strings.Split(a, "")
    for i:=0;i<len(temps);i++{
        if temps[i] ==string('A'){
             temp  = 10
        }else if temps[i] ==string('B'){
             temp  = 11
        }else if temps[i] ==string('C'){
             temp  = 12
        }else if temps[i] == string('D'){
             temp  = 13
        }else if temps[i] ==string('E'){
             temp  = 14
        }else if temps[i] ==string('F'){
             temp  = 15
        }else{
            fmt.Print("输入内容有误")
        }
        var b=math.Pow(16, float64(len(temps)-i-1))
        sum = temp*int(b)+sum
    }
    fmt.Printf("%15d",sum)
}

全部评论

相关推荐

06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
星辰再现:裁员给校招生腾地方
点赞 评论 收藏
分享
uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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