use proconio::{fastout, input, marker::Chars}; #[fastout] fn main() { input! { t: usize, ss: [Chars; t], } for s in &ss { println!("{}", solve(s)); } } fn solve(s: &[char]) -> String { let is_operator = |c: char| c == '+' || c == '-'; let check_placeable_operator = |pos: usize| { pos != s.len() - 1 && (pos == 0 || !is_operator(s[pos - 1])) && !is_operator(s[pos + 1]) }; let mut output = String::new(); output.reserve(s.len()); let mut positive = true; for (i, &c) in s.iter().enumerate() { match c { '1'..='9' => { output.push(c); } '+' => { positive = true; output.push('+'); } '-' => { positive = false; output.push('-'); } '?' => { if positive { output.push('9'); } else if check_placeable_operator(i) { output.push('+'); positive = true; } else { output.push('1'); } } _ => panic!(), } } output }