From 1ccba7112b334c0887bd349966219b38eb9ccfb9 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Sun, 10 Dec 2023 15:55:42 +0200 Subject: Removed some empty problems and solved 2 problems in rust --- codeforces/YetAnotherBrokenKeoard/main.rs | 59 ++++++++++++++++++++++ codeforces/YetAnotherBrokenKeoard/main_input0.txt | 13 +++++ codeforces/YetAnotherBrokenKeoard/main_output0.txt | 12 +++++ .../YetAnotherBrokenKeoard/rust-project.json | 11 ++++ 4 files changed, 95 insertions(+) create mode 100644 codeforces/YetAnotherBrokenKeoard/main.rs create mode 100644 codeforces/YetAnotherBrokenKeoard/main_input0.txt create mode 100644 codeforces/YetAnotherBrokenKeoard/main_output0.txt create mode 100644 codeforces/YetAnotherBrokenKeoard/rust-project.json (limited to 'codeforces/YetAnotherBrokenKeoard') diff --git a/codeforces/YetAnotherBrokenKeoard/main.rs b/codeforces/YetAnotherBrokenKeoard/main.rs new file mode 100644 index 0000000..e39fbd5 --- /dev/null +++ b/codeforces/YetAnotherBrokenKeoard/main.rs @@ -0,0 +1,59 @@ +#[allow(dead_code)] +fn read() -> T { + let mut s = String::new(); + std::io::stdin().read_line(&mut s).ok(); + s.trim().parse().ok().unwrap() +} + +#[allow(dead_code)] +fn read_vec() -> Vec { + read::() + .split_whitespace() + .map(|e| e.parse().ok().unwrap()) + .collect() +} + +#[allow(dead_code)] +fn read_mat(n: u32) -> Vec> { + (0..n).map(|_| read_vec()).collect() +} + +fn solve() { + let inp = read::(); + let s = inp.as_bytes(); + let mut marks = vec![true; s.len()]; + let mut rmost_l = vec![s.iter().position(|&x| x.is_ascii_lowercase()).unwrap_or(0)]; + let mut rmost_h = vec![s.iter().position(|&x| x.is_ascii_uppercase()).unwrap_or(0)]; + for (i, &c) in s.iter().enumerate() { + match c as char { + 'b' => { + marks[i] = false; + marks[rmost_l.pop().unwrap_or(i)] = false; + } + 'B' => { + marks[i] = false; + marks[rmost_h.pop().unwrap_or(i)] = false; + } + _ => {} + }; + if c.is_ascii_uppercase() && c != 'B' as u8 { + rmost_h.push(i); + } else if c.is_ascii_lowercase() && c != 'b' as u8 { + rmost_l.push(i); + } + } + let ans = s + .iter() + .zip(marks.iter()) + .filter_map(|(&x, include)| include.then_some(x as char)) + .collect::(); + println!("{}", ans) +} + +fn main() { + let mut tt = read::(); + while tt > 0 { + solve(); + tt -= 1; + } +} diff --git a/codeforces/YetAnotherBrokenKeoard/main_input0.txt b/codeforces/YetAnotherBrokenKeoard/main_input0.txt new file mode 100644 index 0000000..104142d --- /dev/null +++ b/codeforces/YetAnotherBrokenKeoard/main_input0.txt @@ -0,0 +1,13 @@ +12 +ARaBbbitBaby +YetAnotherBrokenKeyboard +Bubble +Improbable +abbreviable +BbBB +BusyasaBeeinaBedofBloomingBlossoms +CoDEBARbIES +codeforces +bobebobbes +b +TheBBlackbboard diff --git a/codeforces/YetAnotherBrokenKeoard/main_output0.txt b/codeforces/YetAnotherBrokenKeoard/main_output0.txt new file mode 100644 index 0000000..5d42696 --- /dev/null +++ b/codeforces/YetAnotherBrokenKeoard/main_output0.txt @@ -0,0 +1,12 @@ +ity +YetnotherrokenKeoard +le +Imprle +revile + +usyasaeeinaedofloominglossoms +CDARIES +codeforces +es + +helaoard diff --git a/codeforces/YetAnotherBrokenKeoard/rust-project.json b/codeforces/YetAnotherBrokenKeoard/rust-project.json new file mode 100644 index 0000000..a195582 --- /dev/null +++ b/codeforces/YetAnotherBrokenKeoard/rust-project.json @@ -0,0 +1,11 @@ +{ + "sysroot": "/home/omar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu", + "sysroot_src": "/home/omar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/", + "crates": [ + { + "root_module": "main.rs", + "edition": "2021", + "deps": [] + } + ] +} -- cgit v1.2.3