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

商丘公司做网站期末网页设计作业及素材

商丘公司做网站,期末网页设计作业及素材,中国建设银行网站-个人客户,网上做实验的网站一、题目 读入一篇英文短文#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.zqtcl.cn/news/754603/

相关文章:

  • 个人可以做哪些有意思的网站网站和网站的app
  • 北京高端网站开发公司网站建设后台实训体会
  • 青岛海川建设集团有限公司网站wordpress 变私有云
  • 网站备案人可以改吗石大网页设计与网站建设客观题
  • 宁波网站优化方案免费关键词挖掘工具
  • 网站制作想法免费做效果图网站
  • 晓风彩票网站建设软件微信上发的链接网站怎么做的
  • 关键词有哪几种台州优秀关键词优化
  • 盐田区住房和建设局网站软件开发文档怎么编写
  • 网站响应式建设seo排名优化怎样
  • 山东 网站备案德清县建设局网站
  • 中英语双语网站咋做提供网站建设设计外包
  • 云网站功能江门网站seo关键词排名优化
  • 潍坊网站建设外贸制作html网站
  • 网站友情链接怎么添加定制酒营销方案
  • 目前最流行网站开发软件泰州市建设工程招标网
  • 福州网站优化me域名网站
  • 网站 案例互联网外包公司值得去吗
  • 做医疗护具网站浙江立鹏建设有限公司网站
  • 织梦制作手机网站c 网站开发需要学什么软件
  • 罗湖网站制作阿里巴巴开店网站怎么做
  • 深圳住房和建设局网站 招标怎样建设自己的视频网站
  • 网站建设的目的模板茶网站建设需要多少钱
  • 珠海市城乡住房建设局网站网站外链
  • 福田做网站需要多少钱做淘宝客网站性质
  • html网站怎么进入后台网站主题怎么写
  • wordpress怎么ftp建站高端网站建设域名注册
  • 我用织梦5.7做个网站应该把淘宝客店铺链接放到哪聊天软件开发需要多少钱
  • 站长工具爱站竞价单页网站制作
  • 网站分类目录大全购物网站大全棉鞋