写一个程序分析文本文档(英文文章)中各个词出现的频率并把频率最高的10个词打印出
这个程序主要涉及识别、统计和排序,识别和统计采用结构体、结构体数组 ,排序时冒泡排序法。 由于单词存放用的数组所以会造成空间的浪费,存放单词个数,文章大时,空间可能不足,小时会浪费。冒泡排序法由于比较次数多,效率不会太高。
#include<iostream> #include<fstream> #include<string> using namespace std; struct L{ char a[30]; int n; }; int sum=0; void read(struct L word[]) { ifstream in("text.txt"); in>>noskipws; if(!in) {cout<<"cannot open!"<<endl;return;} char ch,temp[30]; while(in) { int i=0; in>>ch; temp[0]='