开开眼界
import std.stdio;
import std.stream;
int main (char[][] args)
{
int w_total;
int l_total;
ulong c_total;
int[char[]] dictionary;
writefln(" lines words bytes file");
foreach (arg; args[1 .. args.length])
{
int w_cnt, l_cnt;
bool inword;
auto c_cnt = std.file.getSize(arg);
if (c_cnt < 10_000_000)
{
size_t wstart;
auto input = cast(char[])std.file.read(arg);
foreach (j, c; input)
{
if (c == '\n')
++l_cnt;
if (c >= '0' && c <= '9')
{
}
else if (c >= 'a' && c <= 'z' ||
c >= 'A' && c <= 'Z')
{
if (!inword)
{
wstart = j;
inword = true;
++w_cnt;
}
}
else if (inword)
{ auto word = input[wstart .. j];
dictionary[word]++;
inword = false;
}
}
if (inword)
{ auto w = input[wstart .. input.length];
dictionary[w]++;
}
}
else
{
auto f = new BufferedFile(arg);
char[] buf;
while (!f.eof())
{ char c;
f.read(c);
if (c == '\n')
++l_cnt;
if (c >= '0' && c <= '9')
{
if (inword)
buf ~= c;
}
else if (c >= 'a' && c <= 'z' ||
c >= 'A' && c <= 'Z')
{
if (!inword)
{
buf.length = 1;
buf[0] = c;
inword = 1;
++w_cnt;
}
else
buf ~= c;
}
else if (inword)
{
if (++dictionary[buf] == 1)
buf = null;
inword = 0;
}
}
if (inword)
{
dictionary[buf]++;
}
}
writefln("%8s%8s%8s %s\n", l_cnt, w_cnt, c_cnt, arg);
l_total += l_cnt;
w_total += w_cnt;
c_total += c_cnt;
}
if (args.length > 2)
{
writefln("--------------------------------------\n%8s%8s%8s total",
l_total, w_total, c_total);
}
writefln("--------------------------------------");
foreach (word1; dictionary.keys.sort)
{
writefln("%3s %s", dictionary[word1], word1);
}
return 0;
}
import std.stream;
int main (char[][] args)
{
int w_total;
int l_total;
ulong c_total;
int[char[]] dictionary;
writefln(" lines words bytes file");
foreach (arg; args[1 .. args.length])
{
int w_cnt, l_cnt;
bool inword;
auto c_cnt = std.file.getSize(arg);
if (c_cnt < 10_000_000)
{
size_t wstart;
auto input = cast(char[])std.file.read(arg);
foreach (j, c; input)
{
if (c == '\n')
++l_cnt;
if (c >= '0' && c <= '9')
{
}
else if (c >= 'a' && c <= 'z' ||
c >= 'A' && c <= 'Z')
{
if (!inword)
{
wstart = j;
inword = true;
++w_cnt;
}
}
else if (inword)
{ auto word = input[wstart .. j];
dictionary[word]++;
inword = false;
}
}
if (inword)
{ auto w = input[wstart .. input.length];
dictionary[w]++;
}
}
else
{
auto f = new BufferedFile(arg);
char[] buf;
while (!f.eof())
{ char c;
f.read(c);
if (c == '\n')
++l_cnt;
if (c >= '0' && c <= '9')
{
if (inword)
buf ~= c;
}
else if (c >= 'a' && c <= 'z' ||
c >= 'A' && c <= 'Z')
{
if (!inword)
{
buf.length = 1;
buf[0] = c;
inword = 1;
++w_cnt;
}
else
buf ~= c;
}
else if (inword)
{
if (++dictionary[buf] == 1)
buf = null;
inword = 0;
}
}
if (inword)
{
dictionary[buf]++;
}
}
writefln("%8s%8s%8s %s\n", l_cnt, w_cnt, c_cnt, arg);
l_total += l_cnt;
w_total += w_cnt;
c_total += c_cnt;
}
if (args.length > 2)
{
writefln("--------------------------------------\n%8s%8s%8s total",
l_total, w_total, c_total);
}
writefln("--------------------------------------");
foreach (word1; dictionary.keys.sort)
{
writefln("%3s %s", dictionary[word1], word1);
}
return 0;
}
...全文
相关推荐
Introduction.to.Algorithms [麻省理工学院-算法导论]
麻省理工学院 算法导论 Introduction.to.Algorithms,MIT的算法导论,看到他们的算法,开开眼界,加强算法学习~
眼界_csdn
在探讨眼界这个概念时,我们可以从多个角度来解读其内涵和意义。首先,眼界可以被理解为一个人的视野宽广度,即个体对于世界或某一特定事物的认知和理解范围。
人生话题作文:眼界打开之后.doc
【标题】:打开眼界的人生感悟【描述】:本文探讨了眼界打开对于个人成长和认知深化的重要性,通过多个角度展示了眼界拓宽的过程和价值,包括参与活动、阅读书籍、理解世界和自我反思。
眼界.rar
"眼界.rar" 这个压缩包文件的名字暗示了其内容可能与拓宽视野、学习新知或洞察科技趋势有关。由于没有具体的标签信息,我们将根据压缩包内的文件名 "眼界" 来推测其中可能包含的内容。
眼界话题作文精彩段落选编.doc
文章通过马克思、达尔文、鲁迅等多位名人故事,探讨了眼界对个人行动和成就的影响。马克思洞察社会规律,达尔文提出生物进化论,他们的眼界超越常人。眼界不仅影响个人视野,还能激发创新、推动社会进步。培养和提升


