Skip to content

Instantly share code, notes, and snippets.

@itsbth
Created December 15, 2014 01:15
Show Gist options
  • Save itsbth/7757582ae71436773a07 to your computer and use it in GitHub Desktop.
Save itsbth/7757582ae71436773a07 to your computer and use it in GitHub Desktop.
use std::io;
use std::collections::HashMap;
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.ok().unwrap().words() {
let lc = word.to_string().to_ascii_lower();
if words.contains_key(lc.as_slice()) {
match words.get_mut(lc.as_slice()) {
Some(w) => *w += 1,
None => (),
}
} else {
// let cw = "FakeWord";
words.insert(lc.clone(), 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