maxword2time.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 35 行

CPP
35
字号
CTimer timer;
timer.Start();
for(outer.Init(); outer.HasMore(); outer.Next())
{  wordCount++;
}
timer.Stop();
double totalTime = timer.ElapsedTime()*wordCount;
wordCount = 0;
timer.Reset();

for(outer.Init(); outer.HasMore(); outer.Next())
{   word = outer.Current();       // current word for comparison
    wordCount++;

    int count = 0;                // count # occurrences      
    timer.Start();
    for(inner.Init(); inner.HasMore(); inner.Next())
    {   if (inner.Current() == word)   // found another occurrence
        {   count++;
        }
    }
    if (count > maxOccurs)             // maximal so far
    {   maxOccurs = count;
        maxWord = word;
    }
    if (count > maxOccurs)             // maximal so far
    {   maxOccurs = count;
        maxWord = word;
    }
    timer.Stop();
    if (wordCount % 100 == 0)
    {   cout  << timer.CumulativeTime() << "\tof " << totalTime << endl;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?