Skip to content

Instantly share code, notes, and snippets.

@itsbth
Last active August 29, 2015 14:11
Show Gist options
  • Save itsbth/89c1cfe25b045dedf64a to your computer and use it in GitHub Desktop.
Save itsbth/89c1cfe25b045dedf64a to your computer and use it in GitHub Desktop.
use std::io;
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied,Vacant};
use std::ascii::AsciiExt;
fn main() {
let mut words: HashMap<String, uint> = HashMap::new();
for line in io::stdin().lock().lines() {
for word in line.unwrap().words() {
let lc = word.to_string().to_ascii_lower();
match words.entry(lc) {
Occupied(mut entry) => *entry.get_mut() += 1,
Vacant(entry) => { entry.set(1); },
}
}
}
for (word, count) in words.iter() {
println!("{}: {}", *word, *count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment