题解 | #进制转换#
进制转换
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) }