Created
April 5, 2017 18:38
-
-
Save nacardin/c112dff46207f13c7a9554dd766f9eca to your computer and use it in GitHub Desktop.
HackerRank > Algorithms > Implementation > Breaking the Records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{self, Read}; | |
fn line_to_vec<T: std::str::FromStr>(line: &str) -> Vec<T> { | |
line.split_whitespace().map(|x| x.parse::<T>().ok().expect("parse error")).collect::<Vec<T>>() | |
} | |
fn main() { | |
let mut buffer = String::new(); | |
io::stdin().read_to_string(&mut buffer).unwrap(); | |
let mut lines = buffer.lines(); | |
lines.next(); | |
let line2 = lines.next().unwrap(); | |
let scores = line_to_vec::<u32>(line2); | |
let mut lowest = scores[0]; | |
let mut highest = scores[0]; | |
let mut lowest_change_count = 0; | |
let mut highest_change_count = 0; | |
for s in scores { | |
if s < lowest { | |
lowest = s; | |
lowest_change_count += 1; | |
} else if s > highest { | |
highest = s; | |
highest_change_count += 1; | |
} | |
} | |
println!("{} {}", highest_change_count, lowest_change_count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment