CSES - Putka Open 2020 – 5/5 - Results
Submission details
Task:HQ9+
Sender:Hennkka
Submission time:2020-11-27 21:03:14 +0200
Language:Rust
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED15
#2ACCEPTED85
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Code

use std::io::BufRead;

fn solve(n: usize) -> String {
    let mut n = n;
    let mut res = "".to_string();
    while n > 0 {
        if n >= 494 {
            res.push('9');
            n -= 494;
        } else {
            res.push('H');
            n -= 1;
        }
    }
    res
}

fn main() {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let mut lines = stdin.lines();

    let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
    for _ in 0..t {
        let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
        println!("{}", solve(n));
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    fn program_output_len(output: String) -> usize {
        output
            .chars()
            .map(|c| match c {
                'H' | 'Q' => 1,
                '9' => 494,
                '+' => 0,
                _ => panic!("invalid character {}", c),
            })
            .sum()
    }

    fn assert_program(n: usize) {
        assert_eq!(program_output_len(solve(n)), n);
    }

    #[test]
    fn test_samples() {
        assert_program(1);
        assert_program(494);
        assert_program(5);
    }
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
100
10
96
42
77
...

correct output
HHHHHHHHHH
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH...

user output
HHHHHHHHHH
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
100
76364
26254
35192
92572
...

correct output
999999999999999999999999999999...

user output
999999999999999999999999999999...
Truncated