wordcnt.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 36 行
CPP
36 行
// A program for counting the number of occurrences of each word in the
// input file.
//
// M. A. Sridhar
// July 29, 1994
#include "base/base.h"
#include <iostream.h>
main ()
{
CL_String line;
CL_StringIntMap word_map;
long count = 0;
const char* punctuation = " :~{}.();&,!?";
while (line.ReadLine (cin)) {
CL_StringSequence words = line.Split (punctuation);
register long n = words.Size();
for (register long i = 0; i < n; i++) {
if (word_map.IncludesKey (words[i]))
word_map[words[i]]++;
else
word_map.Add (words[i], 1);
}
}
CL_StringIntMapIterator itr (word_map);
CL_StringIntAssoc assoc;
for (itr.Reset (); itr.More (); ) {
assoc = itr.Next();
cout << assoc.key << " " << assoc.value << endl;
}
cout << "Total " << word_map.Size() << " words." << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?