CSES - Datatähti 2024 alku - Results
Submission details
Task:Lumimyrsky
Sender:axka
Submission time:2023-11-06 10:09:17 +0200
Language:Rust
Status:COMPILE ERROR

Compiler report

error[E0599]: no method named `try_into` found for struct `Vec<isize>` in the current scope
  --> input/code.rs:22:6
   |
22 |     .try_into()
   |      ^^^^^^^^ method not found in `Vec<isize>`
   |
   = 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;
/// Input:
/// 0 0 3 3 1 2 2 2 1 0
/// 0 1 2 3 2 2 3 0 1 1
/// output:
/// 1
fn main() -> Result<(), Box<dyn std::error::Error>> {
let nousut: [isize; 2] = stdin().lines().map(|rivi| {
// Lue luvut rivistä
let luvut: Vec<isize> = rivi?
.split_ascii_whitespace()
.map(|s| s.parse())
.collect::<Result<_, _>>()?;
// Laske nousu luvuista
let nousu = luvut
.windows(2)
.fold(0, |acc, arr| acc + (arr[1] - arr[0]).max(0));
Ok(nousu)
}).collect::<Result<Vec<_>, Box<dyn std::error::Error>>>()?
.try_into()
.unwrap();
if nousut[0] < nousut[1] {
println!("1");
} else {
println!("2");
}
Ok(())
}