CSES - Datatähti 2022 loppu - Results
Submission details
Task:Järjestys
Sender:xnor
Submission time:2022-01-22 13:07:02 +0200
Language:Rust
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.01 sdetails

Compiler report

warning: variable `nb` is assigned to, but never used
  --> input/code.rs:19:17
   |
19 |         let mut nb = 0;
   |                 ^^
   |
   = note: `#[warn(unused_variables)]` on by default
   = note: consider using `_nb` instead

warning: 1 warning emitted

Code

use std::io::{stdin, BufRead, BufReader};

fn main() {
    let mut stdin = BufReader::new(stdin());
    let mut cur_line = String::new();


    stdin.read_line(&mut cur_line).unwrap();
    let t: usize = cur_line
        .trim()
        .parse().unwrap();

    for _ in 0..t {
        cur_line.clear();
        stdin.read_line(&mut cur_line).unwrap();
        
        let v = cur_line.as_bytes();
        let mut na = 0;
        let mut nb = 0;

        for b in v {
            match b {
                b'A' => na += 1,
                b'B' => nb += 1,
                _ => (),
            }
        }

        let mut x = 0;

        for i in 0..na {
            if v[i] == b'B' {
                x += 1;
            }
        }

        println!("{}", x);
    }
}

Test details

Test 1

Verdict: ACCEPTED

input
1000
BBAABBBBAAABABBBAABBAABAAAABBB...

correct output
10
10
20
3
20
...

user output
10
10
20
3
20
...
Truncated