题解 | #进制转换#

进制转换

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

package main

import (
    "fmt"
    "bufio"
    "os"
    "strings"
    "math"
)

func main() {
    sc := bufio.NewScanner(os.Stdin)
    sc.Scan()
    s := sc.Text()
    idx := strings.Index(s,"x")
    var res int64
    var list= make([]rune,0,100) 
    for _,c := range s{
        list = append(list,c)
    }
    for i:=idx+1;i<len(list);i++{
        if list[i]>='0'&& list[i]<='9'{
            res+=int64(list[i]-'0')*int64(math.Pow(16,float64(len(list)-1-i)))
        }
        if list[i]>='A'&& list[i]<='F'{
            res+=int64(list[i]-'7')*int64(math.Pow(16,float64(len(list)-1-i)))
        }
    }
    fmt.Print(res)
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-26 18:18
点赞 评论 收藏
分享
迷茫的大四🐶:自信一点,我认为你可以拿到50k,低于50k完全配不上你的能力,兄弟,不要被他们骗了,你可以的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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