题解 | #取近似值#

取近似值

https://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a

use std::io::{self, *};

fn main() {
    let stdin = io::stdin();
    unsafe {
        for line in stdin.lock().lines() {
            let ll = line.unwrap();
            let numbers: Vec<&str> = ll.split(".").collect();
            let a = numbers[0].trim().parse::<i32>().unwrap_or(0);
            // println!("{}", a);
            let mut b = numbers[1].trim().parse::<i32>().unwrap_or(0);
            while b > 10 {
                b = b / 10;
            }
            // println!("{}", b);

            if b >= 5 {
                println!("{}", a + 1);
            } else {
                println!("{}", a);
            }
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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