use std::io::*; use std::str::FromStr; fn main() { exec(read()) } fn exec(s: String) { let mut sum = s.parse::().unwrap(); for _ in (1..99).rev() { if sum / 10 == 0 { break; } sum = calc_sum(sum.to_string()); } println!("{}", sum); } fn calc_sum(s: String) -> i64 { let r = s .chars() .map(|c| c.to_digit(10).unwrap()) .collect::>() .iter() .fold(0, |sum, a| sum + a); let d: i64 = From::from(r); d } fn read() -> T { let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") }