Skip to content

Instantly share code, notes, and snippets.

@CaseyLeask
Created October 29, 2016 03:05
Show Gist options
  • Save CaseyLeask/bd69808b64c877ce1a71d61b1e43084b to your computer and use it in GitHub Desktop.
Save CaseyLeask/bd69808b64c877ce1a71d61b1e43084b to your computer and use it in GitHub Desktop.
use std::io;
use std::io::BufRead;
use std::collections::HashMap;
fn main() {
let stdin = io::stdin();
let lines: Vec<std::string::String> = stdin.lock().lines().map(|l| l.unwrap()).collect();
let trimmed = lines[0].trim();
let mut count = 0;
match trimmed.parse::<usize>() {
Ok(i) => count = i,
Err(..) => println!("this was not an integer: {}", trimmed)
};
let entries = (1..).take(count).fold(HashMap::new(), |mut acc, i| {
let words: Vec<&str> = lines[i].trim().split_whitespace().collect();
let (key, value) = (words[0], words[1]);
acc.insert(key, value);
acc
});
let queries = lines.iter().cloned().skip(count+1);
for query in queries {
match entries.get::<str>(&query) {
Some(value) => println!("{}={}", &query, value),
_ => println!("Not found"),
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment