取近似值-golang版本

取近似值

http://www.nowcoder.com/questionTerminal/3ab09737afb645cc82c35d56a5ce802a

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    text, _ := reader.ReadString('\n')
    index := strings.LastIndex(text, ".")
    lastValue, _ := strconv.Atoi(string(text[index+1]))
    firstValue, _ := strconv.Atoi(text[:index])
    if lastValue >= 5 {
        fmt.Println(firstValue + 1)
    } else {
        fmt.Println(firstValue)
    }

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务