Bracket Matching by Badewanne3

use std::io::*;fn main(){let i=stdin();for p in i.lock().lines(){let z=|l:&[u8]|{let(b,r,mut t)=(b"([{<)]}>","failed at: ".to_owned(),vec![]);for i in 0..l.len(){match b.iter().position(|&x|x==l[i]).unwrap(){j@0...3=>t.push(b[j]),j=>{if t.pop().map_or(false,|c|c!=b[j-4]){return r+&String::from_utf8_lossy(&l[i..]).to_string();}}}}if t.len()==0{"yes".to_owned()}else{r+"EOL"}};println!("{}",z(p.unwrap().as_bytes()));}}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page