Skip to content

Instantly share code, notes, and snippets.

@claudioacioli
Created June 5, 2021 19:05
Show Gist options
  • Save claudioacioli/7e6fca68123bbcc053c587a746df368d to your computer and use it in GitHub Desktop.
Save claudioacioli/7e6fca68123bbcc053c587a746df368d to your computer and use it in GitHub Desktop.
use std::io;
fn main() {
let a = get_arr();
let b = get_arr();
let result = compare_rates(&a, &b);
println!("{} {}", result.0, result.1);
}
fn get_arr() -> Vec<u8> {
const N :usize = 3;
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap_or(0);
let mut arr = vec![0; N];
for (i, value) in s.split_whitespace().enumerate() {
if i >= N {
break;
}
arr[i] = value.parse::<u8>().unwrap_or(0);
}
arr
}
fn compare_rates(a :&[u8], b :&[u8]) -> (u8, u8) {
if a.len() != 3 || b.len() != 3 {
return (0, 0);
}
let mut score_a :u8 = 0;
let mut score_b :u8 = 0;
for i in 0..3 {
if a[i] > b[i] {
score_a += 1;
} else if b[i] > a[i] {
score_b += 1;
}
}
(score_a, score_b)
}
#[test]
fn test_compare_rates() {
assert_eq!((1, 2), compare_rates(&[95, 50, 75], &[100, 45, 95]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment