use std::io; use std::io::BufRead; fn main() { let reader = io::stdin(); let mut buffer = reader.lock(); //let writer = io::stdout(); let mut sum = 0; loop { let consumed = match buffer.fill_buf() { Ok(bytes) => { sum += bytes.iter().fold(0, |acc, &item| if item > 48 && item < 58 { acc + item as u32 - 48 } else { acc }); bytes.len() }, Err(_) => panic!() }; if consumed == 0 {break;} buffer.consume(consumed); } println!("{}", sum); }