题解 | #扭蛋机#

扭蛋机

https://www.nowcoder.com/practice/9d26441a396242a9a0f7d2106fc130c7

package main

import (
	"fmt"
)

func reverseString(s string) string {
	runes := []rune(s)
	for from, to := 0, len(runes)-1; from < to; from, to = from+1, to-1 {
		runes[from], runes[to] = runes[to], runes[from]
	}
	return string(runes)
}

func main() {
	n := 0
	_, _ = fmt.Scan(&n)
    // fmt.Println(n)
	res := ""

	for n > 0 {
		if n%2 == 0 {
			n = (n - 2) / 2
			res += "3"
		} else {
			n = (n - 1) / 2
			res += "2"
		}
	}
	
    fmt.Println(reverseString(res))
}

全部评论

相关推荐

走不到的路就这样算了吗:大佬硬气
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务