CSES - Datatähti 2024 alku - Results
Submission details
Task:Monistus
Sender:Roopekt
Submission time:2023-11-07 20:21:46 +0200
Language:Rust
Status:COMPILE ERROR

Compiler report

error[E0599]: no method named `try_into` found for type `u32` in the current scope
  --> input/code.rs:16:33
   |
16 |                     .take(digit.try_into().unwrap())
   |                                 ^^^^^^^^ method not found in `u32`
   |
   = help: items from traits can only be used if the trait is in scope
   = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
1  | use std::convert::TryInto;
   |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.

Code

use std::io::stdin;

fn main() {
    let mut input = stdin().lines();

    let text = input.next().unwrap().unwrap();
    let mut char_stack: Vec<char> = text.chars().rev().collect();
    let mut output = String::new();

    while let Some(character) = char_stack.pop() {
        match character.to_digit(10) {
            Some(digit) => {
                let to_duplicate: Vec<char> = char_stack
                    .iter()
                    .rev()
                    .take(digit.try_into().unwrap())
                    .copied()
                    .collect();

                char_stack.extend(to_duplicate.iter().rev());
            },
            None => {
                output.push(character);
            }
        }
    }

    println!("{output}");
}