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

射阳做企业网站哪家好安庆商城网站开发

射阳做企业网站哪家好,安庆商城网站开发,chatgpt 网站,wordpress添加随机图片文章目录使用标准库#xff1a;文本查询程序文本查询程序设计数据结构在类之间共享数据自己的文本查询程序书中的文本查询程序使用标准库#xff1a;文本查询程序 我们将实现一个简单的文本查询程序#xff0c;作为标准库相关内容学习的总结。 我们的程序允许用户在一个给… 文章目录使用标准库文本查询程序文本查询程序设计数据结构在类之间共享数据自己的文本查询程序书中的文本查询程序使用标准库文本查询程序 我们将实现一个简单的文本查询程序作为标准库相关内容学习的总结。 我们的程序允许用户在一个给定文件中查询单词。查询结果是单词在文件中出现的次数及其所在行的列表。如果一个单词在一行中出现多次此行只列出一次。行会按照升序输出。 文本查询程序设计 数据结构 我们定义一个保存输入文件的类将这个类命名为TextQuery它包含一个vector和一个map。vector用来保存输入文件的文本map用来关联每个单词和它出现的行号的set。这个类将会有一个用来读取给定输入文件的构造函数和一个执行查询的操作。 在类之间共享数据 自己的文本查询程序 TextQuery类 #ifndef __TEXTQUERY__ #define __TEXTQUERY__#includestring #includeiostream #includevector #includemap #includeset #includememory #includefstream #includesstream #includeQueryResult.h using namespace std;class TextQuery { public:TextQuery() {}TextQuery(ifstream ifs);QueryResult query(string s); private:shared_ptrvectorstringstrText;shared_ptrmapstring,setintstrNum; };TextQuery::TextQuery(ifstream ifs) {string str;vectorstringvec;while (getline(ifs, str)) {vec.push_back(str);}strText make_sharedvectorstring(vec);mapstring, setintmp;int LineNum 1;for (auto a : *strText) {istringstream vecStr(a);string tmp;while (vecStr tmp) {mp[tmp].insert(LineNum);}LineNum;}strNum make_sharedmapstring, setint(mp);cout success1endl; }QueryResult TextQuery::query(string s) {if (strNum-find(s) strNum-cend()) {return QueryResult(s, 0, strText, strNum);}int num (strNum-at(s)).size();cout num:num endl;return QueryResult(s,num, strText, strNum); }#endif QueryResult类 #ifndef __QUERYRESULT__ #define __QUERYRESULT__#includestring #includeiostream #includevector #includemap #includeset #includememory using namespace std;class QueryResult { public:QueryResult() {}QueryResult(strings,int num,shared_ptrvectorstringstrText, shared_ptrmapstring, setintstrNum):str(s),nums(num),strText(strText),strNum(strNum){}string getStr() { return str; }int getNums() { return nums; }shared_ptrvectorstring getStrText() { return strText; }shared_ptrmapstring, setintgetStrNum() { return strNum; } private:string str;int nums;shared_ptrvectorstringstrText;shared_ptrmapstring, setintstrNum; };ostream print(ostream os, QueryResult qr) {if (qr.getNums() 0) {os qr.getStr() occurs qr.getNums() time endl;return os;}os qr.getStr() occurs qr.getNums() (qr.getNums() 1 ? times : time) endl;shared_ptrmapstring, setint mp qr.getStrNum();shared_ptrvectorstringvec qr.getStrText();setintstmp-at(qr.getStr());for (auto n:st) {os (line n ) vec-at(n-1) endl;}return os;}#endif 测试程序 void testTextQuery() {ifstream infile(test.txt);TextQuery tq(infile);while (true) {cout enter word to look for,or q tu quit:endl;string s;if (!(cin s) || s q)break;print(cout, tq.query(s)) endl;} }书中的文本查询程序 TextQuery类 #ifndef __TEXTQUERY__ #define __TEXTQUERY__#includestring #includeiostream #includevector #includemap #includeset #includememory #includefstream #includesstream #includeQueryResult.h using namespace std;class TextQuery { public:using line_no vectorstring::size_type;TextQuery() {}TextQuery(ifstream ifs);QueryResult query(const string s)const; private:shared_ptrvectorstringstrText;mapstring, shared_ptrsetline_nostrNum; };TextQuery::TextQuery(ifstream ifs):strText(new vectorstring) {string str;while (getline(ifs, str)) {strText-push_back(str);int n strText-size() - 1;istringstream vecStr(str);string word;while (vecStr word) {auto lines strNum[word];//lines是一个shared_ptrif (!lines)//在我们第一次遇到这个单词时此指针为空lines.reset(new setline_no);//分配一个新的setlines-insert(n);}} }QueryResult TextQuery::query(const string s)const {static shared_ptrsetline_nonodata(new setline_no);if (strNum.find(s) strNum.cend()) {return QueryResult(s,strText, nodata);}elsereturn QueryResult(s,strText, strNum.find(s)-second); }#endif QueryResult类 #ifndef __QUERYRESULT__ #define __QUERYRESULT__#includestring #includeiostream #includevector #includemap #includeset #includememory using namespace std;class QueryResult {friend ostream print(ostream os, const QueryResult qr); public:using line_no vectorstring::size_type;QueryResult() {}QueryResult(const strings,shared_ptrvectorstringstrText, shared_ptrsetline_nostrNum):str(s),strText(strText),strNum(strNum){}private:string str;shared_ptrvectorstringstrText;shared_ptrsetline_nostrNum; };ostream print(ostream os, const QueryResult qr) {os qr.str occurs qr.strNum-size() (qr.strNum-size() 1 ? times : time) endl;for (auto n:*qr.strNum) {os \t(line n1 ) qr.strText-at(n) endl;}return os;}#endif
http://wiki.neutronadmin.com/news/163465/

相关文章:

  • 深圳网站建设推进wordpress免签约微信支付宝
  • 微网站菜单做文员的网站知乎
  • 太原市建设厅官方网站有域名 空间如何建网站
  • 网页建设技术和网站策划书网页游戏排行榜前十名评论
  • 上海闸北网站建设wordpress内页显示副标题
  • 手把手做网站龙岗坪地网站建设
  • 松江网站建设推广个人网站样式
  • 唐山滦县网站建设三亚网站建设方案
  • 贷款网站建设方案中智软件开发有限公司
  • 高端模板建站报价wordpress管理网站
  • 网站制作新手烟台网站制作厂家电话
  • 企业网站属于哪种网站类型游戏网站网页模板html
  • 旅游网站策划书西安公司团建活动好去处
  • 医院网站 行风建设合肥做网站的的公司
  • 家教网站建设模板湘潭网站建设 磐石网络最好
  • 深圳专业建站公司技术好百度大数据中心
  • 网站建设技术概述淮安网站建设公司
  • 绵阳网站建设价格企业策划书范文
  • 济南网站建站模板wordpress 团队 主题
  • 网站建设整改情况汇报怎么才可以做网站
  • 自己做企业网站详细流程免费ppt免费模板官网
  • 长春火车站有几个互联网营销师培训
  • 课程网站资源建设小结东莞做网站
  • 网站如何备案要关站吗网站构建的基本流程
  • 如何做个网站推广自己产品佛山微网站建设哪家专业
  • 衡阳做淘宝网站与做机器人有关的网站
  • 网站建设属于什么经营类型寺庙网站开发策划书
  • 规划网站的思路wordpress开发工作
  • 保健品手机网站模板什么网站可以做数据图
  • 福州思企互联网站建设公司怎么样携程网站联盟