当前位置: 首页 > news >正文

网站源码之家深圳网站优化网站

网站源码之家,深圳网站优化网站,怎么创建网站 优帮云,教师专用ppt模板免费下载一、题目 读入一篇英文短文#xff0c;去除介词、连词、冠词、副词、代词等非关键性单词后#xff0c;统计每个单词出现的次数#xff0c;并将单词按出现次数的降序和单词字符的升序进行显示5个单词。 二、算法 1. 通过fstream库创建fstream流对象#xff0c;并从…一、题目 读入一篇英文短文去除介词、连词、冠词、副词、代词等非关键性单词后统计每个单词出现的次数并将单词按出现次数的降序和单词字符的升序进行显示5个单词。 二、算法 1. 通过fstream库创建fstream流对象并从文件中读取全部字符存入内存。 2. 将内存的字符串进行空格、标点符号、换行符的分割若分割后的单词属于需要记入统计的单词则将其存入map容器中通过map进行词频统计。 3. 对map中的词频统计结果写入vector中进行排序并按照规定的排序顺序进行打印。 三、代码 #define _CRT_SECURE_NO_WARNINGS 1#include iostream #include fstream #include cstring #include map #include vector #include algorithm using namespace std;// 不计入统计的单词表介词、连词、冠词、副词、代词 vectorstring g_delWord {to, in, on, for, of, from, between, behind, by, about, at, with, than,a, an, the, this, that, there,and, but, or, so, yet,often, very, then, therefore,i, you, we, he, she, my, your, hes, her, our, us, it, they, them,am, is, are, was, were, be,when, where, who, what, how,will, would, can, could };// 仿函数 struct Compare {bool operator()(const pairstring, int e1, const pairstring, int e2){return e1.second e2.second;} };int main() {// 1. 读入文件数据// ofstream写文件// ifstream读文件// fstream读写文件fstream f;// ios::in// ios::out// ios::app追加写配合ios::out使用// ios::trunc覆盖写配合ios::out使用// ios::binary以二进制的形式f.open(./test1.txt, ios::in);if (!f.is_open()){cout file open failed! endl;return 1;}char text[4096] { 0 };f.read(text, 4096);// 2. 分割字符串存入mapmapstring, int wordMap;const char* cut ,.!?;:\n; // 部分单词分隔符char* w strtok(text, cut);while (w){string word w;// 单词转小写string lwrWord;transform(word.begin(), word.end(), back_inserter(lwrWord), ::tolower);// 排除不计入统计的单词if (find(g_delWord.begin(), g_delWord.end(), lwrWord) g_delWord.end()){wordMap[lwrWord];// map 的 “[]”重载有插入、查询、修改功能返回值为键值对的second值或false}w strtok(NULL, cut);}// 3. 词频排序vectorpairstring, int wordVec;for (auto e : wordMap){wordVec.push_back(e);}// sort是基于快速排序实现的算法是不稳定的排序算法可用stable_sort代替stable_sort(wordVec.begin(), wordVec.end(), Compare());for (int i 0; i 5; i){cout wordVec[i].first , wordVec[i].second endl;}return 0; } 四、测试 测试文档test1.txt No one can help others as much as you do. No one can express himself like you. No one can express what you want to convey. No one can comfort others in your own way. No one can be as understanding as you are. No one can feel happy, carefree, and no one can smile as much as you do. In a word, no one can show your features to anyone else. hi, how are you? I love you! 运行结果
http://www.pierceye.com/news/712757/

相关文章:

  • 网站制作资质2017建设厅网站
  • 网站系统开发毕业设计哈尔滨seo优化软件
  • 南通企业网站网站制作的书籍
  • 长沙网站收录怎么网站能找人做装修事
  • 鞍山网站制作谁家好2021没封的网站有人分享吗
  • 网站建设公司net2006iis虚拟网站
  • 有哪些竞价网站wordpress手机端网站模板下载
  • 浙江建设厅网站施工员报名莱芜庞允盟
  • 网站建设 销售 知乎云南网站设计外包
  • 网站建设怎么学习phpcms门户网站
  • 佛山营销型网站定制三站合一网站建设方案
  • 广州市哪有做网站的查找全国免费网站建设
  • 江门seo网站推广跳动爱心代码html教程
  • 网站退出率网易搜索引擎入口
  • 企业网站建设方讯长沙城乡建设网站
  • 手机网站建设优化软件做网站空间费用是什么意思
  • 网站透明效果工厂网站建设流程图
  • 崇安网站建设广州本地门户网站
  • 网站建设公司河南郑州wordpress 单栏
  • 盐城市城镇化建设投资集团网站深圳专业企业网站制作哪家好
  • 绵阳做网站哪家公司好青岛手工活外发加工网
  • 如何调用网站列表页河北建基官网
  • 灰系网站wordpress 谷歌收录
  • 怎么把网站关掉wordpress小白
  • 开发网站合作协议网站建设团购
  • 管理手机网站网站规划与建设重要性理解与体会
  • 小辰青岛网站建设自己怎么开网站
  • 天津市建设工程合同备案网站网站建设 开发 模板
  • 外贸网站建设公司报价jsp网站建设技术案例
  • 旅行社英文模板网站织梦 网站迁移