Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve 06A to... #29

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Chapter06/Problem06A/main.rs
Original file line number Diff line number Diff line change
@@ -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::<i32>().unwrap()
};

let mut ret: Vec<String> = 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"),
};
}
}