use std::fs::File; use std::io::Read; // use std::cmp; fn digitsum(mut a: i32) -> i32 { let mut b = 0; loop{ b += a % 10; a /= 10; if a == 0{ break; } } return b; } fn main() { let inputstatus = 10; let mut buf = String::new(); let filename = "inputrust.txt"; if inputstatus == 0 { let mut f = File::open(filename).expect("file not found"); f.read_to_string(&mut buf) .expect("something went wrong reading the file"); } else { std::io::stdin().read_to_string(&mut buf).unwrap(); } let mut iter = buf.split_whitespace(); let mut n: i32 = iter.next().unwrap().parse().unwrap(); for _ in 0..10 { n = digitsum(n); } println!("{}", n); }