取近似值-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)
}
}
查看8道真题和解析