example 6

This commit is contained in:
Alexander Zhirov 2021-11-09 22:06:20 +03:00
parent 3f11e9e2df
commit ef8298407a
4 changed files with 4513 additions and 0 deletions

15
src/example_6/.gitignore vendored Normal file
View File

@ -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

9
src/example_6/dub.json Normal file
View File

@ -0,0 +1,9 @@
{
"authors": [
"alexander"
],
"description": "Подсчет частот. Лямбда-функции.",
"license": "proprietary",
"name": "example_6",
"targetPath": "bin"
}

View File

@ -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