example 6
This commit is contained in:
parent
3f11e9e2df
commit
ef8298407a
|
@ -0,0 +1,15 @@
|
||||||
|
.dub
|
||||||
|
docs.json
|
||||||
|
__dummy.html
|
||||||
|
docs/
|
||||||
|
/example_6
|
||||||
|
example_6.so
|
||||||
|
example_6.dylib
|
||||||
|
example_6.dll
|
||||||
|
example_6.a
|
||||||
|
example_6.lib
|
||||||
|
example_6-test-*
|
||||||
|
*.exe
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.lst
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"authors": [
|
||||||
|
"alexander"
|
||||||
|
],
|
||||||
|
"description": "Подсчет частот. Лямбда-функции.",
|
||||||
|
"license": "proprietary",
|
||||||
|
"name": "example_6",
|
||||||
|
"targetPath": "bin"
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
import std.stdio, std.string, std.algorithm;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// auto f = File("./src/example_6/source/hamlet.txt", "r");
|
||||||
|
auto f = File("./source/hamlet.txt", "r");
|
||||||
|
|
||||||
|
uint[string] freqs;
|
||||||
|
foreach (line; f.byLine)
|
||||||
|
{
|
||||||
|
foreach (word; strip(line).split())
|
||||||
|
{
|
||||||
|
++freqs[word.idup];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] words = freqs.keys;
|
||||||
|
sort!((a, b) {
|
||||||
|
return freqs[a] < freqs[b];
|
||||||
|
}) (words);
|
||||||
|
|
||||||
|
foreach (word; words)
|
||||||
|
{
|
||||||
|
writefln("%6u\t%s", freqs[word], word);
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue