https://atcoder.jp/contests/abc243/tasks/abc243_a
Pythonではこのようにcycleを使うと分かりやすいですが、
for S, ret in izip(cycle((A, B, C)), cycle('FMT')): ...
Rustでも同様の方法が使えます。
let v = vec![f, m, t]; for p in v.iter().cycle() { ... }
cycleはIteratorのメソッドとして与えられます。
// Shampoo #![allow(non_snake_case)] fn read<T: std::str::FromStr>() -> T { let mut line = String::new(); std::io::stdin().read_line(&mut line).ok(); line.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } struct Person { symbol: char, usage: i32, } fn main() { let v = read_vec(); let mut V = v[0]; let f = Person { symbol: 'F', usage: v[1] }; let m = Person { symbol: 'M', usage: v[2] }; let t = Person { symbol: 'T', usage: v[3] }; let v = vec![f, m, t]; for p in v.iter().cycle() { V -= p.usage; if V < 0 { println!("{}", p.symbol); break; } } }