c++词频统计,高手进,要求做 200
词频统计:输入任意长度的英文文本(空行表示结束),输出出现频率最高的前三个单词(以空格分隔单词)及其出现次数,相同次序的按字母序输出。提示:链表,动态内存分配,排序输入1...
词频统计:输入任意长度的英文文本(空行表示结束),输出出现频率最高的前三个单词(以空格分隔单词)及其出现次数,相同次序的按字母序输出。
提示:链表,动态内存分配,排序
输入1:
I am sinking in deep mud
and there is no solid ground
I am out in deep water
and the waves are about to drown me.
I am worn out from calling for help
and my throat is aching
I have strained my eyes
looking for your help
输出1:
I 4
am 3
and 3 展开
提示:链表,动态内存分配,排序
输入1:
I am sinking in deep mud
and there is no solid ground
I am out in deep water
and the waves are about to drown me.
I am worn out from calling for help
and my throat is aching
I have strained my eyes
looking for your help
输出1:
I 4
am 3
and 3 展开
1个回答
展开全部
#include <map>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void display_map(map<string, int> &wmap);
int main()
{
const char *szInputFileName="Text.txt";
ifstream ifs(szInputFileName);
string szTemp;
map<string, int> wmap;
while (ifs>>szTemp)
wmap[szTemp]++;
display_map(wmap);
return false;
}
void display_map(map<string, int> &wmap)
{
map<string, int>::const_iterator map_it;
for (map_it=wmap.begin(); map_it!=wmap.end();map_it++)
{
cout<<"(/""<<map_it->first<<"/","<<map_it->second<<")"<<endl;
}
}
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void display_map(map<string, int> &wmap);
int main()
{
const char *szInputFileName="Text.txt";
ifstream ifs(szInputFileName);
string szTemp;
map<string, int> wmap;
while (ifs>>szTemp)
wmap[szTemp]++;
display_map(wmap);
return false;
}
void display_map(map<string, int> &wmap)
{
map<string, int>::const_iterator map_it;
for (map_it=wmap.begin(); map_it!=wmap.end();map_it++)
{
cout<<"(/""<<map_it->first<<"/","<<map_it->second<<")"<<endl;
}
}
追问
你这个不行,错的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |