Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
import std.stdio, std.string;
void main() {
uint[string] dictionary;
foreach (line; stdin.byLine()) {
// Break sentence into words
// Add each word in the sentence to the vocabulary
foreach (word; splitter(strip(line))) {
if (word in dictionary) continue; // Nothing to do
auto newlD = dictionary.length;
dictionary[word] = newlD;
writeln(newlD, '\t', word);
}
}
}
as Box<Reader/Writer>
.use std::collections::HashMap;
use std::io::{stdin, BufRead, Result};
fn main() {
word_count().unwrap();
}
fn word_count() -> Result<()> {
let mut dictionary = HashMap::new();
let stdin = stdin();
for line in stdin.lock().lines() {
for word in try!(line).trim().split(' ') {
let new_len = dictionary.len();
if dictionary.insert(word.to_owned(), new_len).is_none() {
println!("{}\t{}", new_len, word);
}
}
}
Ok( () )
}
case x of
Some 0 -> 1
Some x -> x*2
Nothing -> 0
grep -oP '\w+' $@ | sort | uniq -c
Сравниваем Nim и Rust