Created
December 15, 2014 01:15
-
-
Save itsbth/7757582ae71436773a07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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