use std::io;

/**
let mut input = String::new();

    io::stdin()
        .read_line(&mut input)
        .expect("correct input");

    let res = input.trim()
        .split(' ')
        .map(|a| a.parse::<i32>())
        .map(|a| a.expect("parsed error"))
        .fold(0i32, |sum, a| sum + a);

    println!("{:?}", res);

    let words = ["alpha", "beta", "gamma"];

    // chars() returns an iterator
    let merged: String = words.iter()
        .flat_map(|s| s.chars())
        .collect();
    assert_eq!(merged, "alphabetagamma");
**/
fn main() {
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("correct input");

    let num: i32 = input.trim().parse().unwrap();

    let sum = (1..num).filter(|x| x % 3 == 0 || x % 5 == 0).map(|x| {
        println!("{}", x);
        x
    }).fold(0, |sum, a| sum + a);
    println!("{}", sum)
}


评论