hi all.
i solved ANARC05H with c++. but i got nzec when implemented it with rust.
this is my rust code. can anyone tell me what is wrong with this code? i'm new in rust.
use std::io;
fn solve(position: usize, previous_accumulation: i32, inp_length: usize, inp: &String) -> i32 {
if position >= inp_length { return 1; }
let mut result: i32 = 0;
let mut accumulation: i32 = 0;
let mut index: usize = position;
while index < inp_length {
accumulation += inp.chars().nth(index).unwrap().to_digit(10).unwrap() as i32;
index += 1;
if accumulation >= previous_accumulation {
result += solve(index, accumulation, inp_length, inp);
}
}
return result;
}
fn main() {
let mut inp: String = String::new();
let mut num: i32 = 0;
loop {
inp.clear();
io::stdin().read_line(&mut inp);
let first_char = inp.chars().nth(0).unwrap();
if !first_char.is_digit(10) { break; }
let inp_length = inp.chars().count() - 1;
num += 1;
println!("{}. {}", num, solve(0, 0, inp_length, &inp));
}
}
thanks a lot.