一道关于文本字符处理的程序,大家帮个忙

来源:百度知道 编辑:UC知道 时间:2024/06/09 21:05:49
要求输入任意一段英文,根据所输英文中个单词出现概率的高低输出前5个单词,具有输入输出界面。

注意:是统计单词的出现概率按高低输出前5个,不是统计字母的概率
要完整的C源代码,谢了

//我以前写过类似的,现在修改了一下,能满足你的要求,绝对原创,但是C++ code,不好意思,如果你想要C code的话,50分绝对不够的,代码长度至少比现在长三倍
#if _MSVC_VER <= 1200
#pragma warning( disable: 4786)//消除vc6对模板支持不好的警告
#endif
#pragma warning( disable: 4996)//消除.net对不安全数据的警告
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <functional>
#include <stdio.h>
using namespace std;

typedef pair<string,int> MyData;
template<class _Ty>
struct MySort
: public binary_function<_Ty, _Ty, bool>
{ // functor for operator>
bool operator()(const _Ty& _Left, const _Ty& _Right) const
{ // apply operator> to operands
return _Left.second>_Right.second;
}
};

bool FindKeyWord(vector<MyData> &vecWord,string &strKey)
{
vector<MyData>::iterator iter;
for(iter=vecWord.begin();iter!=vecWord.end();iter++)
{