From 67281a1c8088456bf4c28e4703bd399ca7a71903 Mon Sep 17 00:00:00 2001 From: pmnxis Date: Thu, 20 Jan 2022 20:33:24 +0900 Subject: [PATCH] Solve 06A --- Chapter06/Problem06A/main.rs | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Chapter06/Problem06A/main.rs diff --git a/Chapter06/Problem06A/main.rs b/Chapter06/Problem06A/main.rs new file mode 100644 index 0000000..8ac43f0 --- /dev/null +++ b/Chapter06/Problem06A/main.rs @@ -0,0 +1,39 @@ +fn solve(line: &String) -> bool { + let mut k = 0; + for c in line.chars() { + match c { + '(' => k = k + 1, + ')' => k = k - 1, + _ => return k == 0, + } + if k < 0 { + return false; + } + } + k == 0 +} + +fn main() { + let lines = { + let nr_string = { + let mut buffer = String::new(); + std::io::stdin().read_line(&mut buffer).expect("Fail"); + buffer.trim().parse::().unwrap() + }; + + let mut ret: Vec = Vec::new(); + for _ in 0..nr_string { + let mut tmp = String::new(); + std::io::stdin().read_line(&mut tmp).unwrap(); + ret.push(tmp); + } + ret + }; + + for line in lines.iter() { + match solve(&line) { + true => println!("YES"), + false => println!("NO"), + }; + } +}