Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::BTreeMap;
- use std::io;
- use std::io::BufRead;
- fn main() {
- let mut counts: BTreeMap<String, isize> = BTreeMap::new();
- let stdin = io::stdin();
- for line_result in stdin.lock().lines() {
- match line_result {
- Ok(line) => {
- let lowercase_line = line.to_lowercase();
- let words = lowercase_line.split(|c: char| {
- !(c.is_alphabetic() || c == ''')
- }).filter(|s| !s.is_empty());
- for word in words {
- *(counts.entry(word.to_string()).or_insert(0)) += 1;
- }
- },
- Err(e) => {
- panic!("Error parsing stdin: {:?}", e);
- }
- }
- }
- for (key, value) in counts.iter() {
- println!("{} {}", key, value);
- }
- }
- counts = Dict{AbstractString, UInt64}()
- for line in eachline(STDIN)
- for word in matchall(r"[a-z']+", lowercase(line))
- counts[word] = get(counts, word, 0) + 1
- end
- end
- for (word, count) in sort(collect(counts))
- println("$word $count")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement