题解 | 矩阵计算

矩阵计算

https://www.nowcoder.com/practice/0c83231923c541d2aa15861571831ee5

fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).expect("Failed to read line");
    let hander:Vec<i32> = input
    .trim()
    .split_whitespace()
    .map(|x| x.parse().expect("Failed to parse number"))
    .collect();

    let N=hander[0];
    let M=hander[1];
    input.clear();

    let mut total = 0;
    for i in 0..N{
        std::io::stdin().read_line(&mut input).unwrap();
        let mut line= input
        .trim()
        .split_whitespace()
        .filter(|x| x.parse::<i32>().unwrap()>0)
        .map(|x| x.parse::<i32>().unwrap())
        .sum::<i32>();

        total += line;
         input.clear();
    }
    println!("{}", total);
}

全部评论

相关推荐

脑袋锈住了:你这算啥,哥们中科院中强所硕士,本科211,叫我去干分拣,时薪20
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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