统计文本中英文单词的出现频率

/*
 *@author:郑海波 http://blog.csdn.net/NUPTboyZHB
 *参考:实验室小熊
 *注:有删改
 */
#pragma warning(disable:4786)
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
void topK(const int &K)
{
	double t=clock();

	ifstream infile;
	infile.open("test.txt");
	if (!infile)
		cout<<"can not open file"<wordcount;

	while(true)
	{
		infile>>s;
		if(infile.eof()) break;
		wordcount[s]++;
	}
	cout<<"单词种类:"<";
	priority_queue< pair< int,string >,vector< pair< int,string > >,greater< pair< int,string> > > queueK;
	for (map::iterator iter=wordcount.begin(); iter!=wordcount.end(); iter++)
	{
		queueK.push(make_pair(iter->second,iter->first));
		if(queueK.size()>K)
			queueK.pop();
	}
	pairtmp;
	priority_queue< pair< int,string >,vector< pair< int,string > >,less< pair< int,string> > > queueKless;
	while (!queueK.empty())
	{
		tmp=queueK.top();
		queueK.pop();
		queueKless.push(tmp);
	}
	while(!queueKless.empty())
	{
		tmp=queueKless.top();
		queueKless.pop();
		cout<"<>k;
		if(k<=0)break;
		topK(k);
	}
	return 0;
}

你可能感兴趣的:(笔试)