Skip to content

Instantly share code, notes, and snippets.

@icub3d
Created January 12, 2026 19:58
Show Gist options
  • Select an option

  • Save icub3d/a1908963fac8152e3883e7bd93f6f1a2 to your computer and use it in GitHub Desktop.

Select an option

Save icub3d/a1908963fac8152e3883e7bd93f6f1a2 to your computer and use it in GitHub Desktop.
Kattis ptice
use std::io::{Read, stdin};
fn main() {
let mut s = String::new();
stdin().read_to_string(&mut s).unwrap();
let quiz = s.lines().nth(1).unwrap();
let patterns = [("Adrian", "ABC"), ("Bruno", "BABC"), ("Goran", "CCAABB")];
let scores = patterns
.iter()
.map(|&(n, c)| {
(
n,
quiz.chars()
.zip(c.chars().cycle())
.filter(|(a, g)| a == g)
.count(),
)
})
.collect::<Vec<_>>();
let max = scores.iter().max_by_key(|(_, s)| s).unwrap().1;
println!("{max}");
scores
.iter()
.filter(|(_, s)| *s == max)
.for_each(|(n, _)| println!("{n}"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment