该课题来源于UVA中Searching the Web的题目:https://vjudge.net/problem/UVA-1597

按照题目的说法,我对按照特定格式输入的文章中的词语合成字典,以满足后期的快速查找。

针对于字典的合成途径,我利用了STL中的map与set的嵌套形成了一种特定的数据结构来解析文章中的单词

 #include<map>
#include<iostream>
#include<set>
#include<algorithm>
#include<string>
#include<cctype>
#include<sstream>
using namespace std;
struct newpair
{
int article;
int line;
bool operator<(const newpair b) const
{
return this->line < b.line;
}
};
typedef map<string,set<newpair> > BIGMAP;
typedef set<newpair>::iterator SET_pair_ITER;
typedef map<string,set<newpair> >::iterator BIGMAP_iter; BIGMAP maper;
string psd[];
int maxline; int checkmaper()
{
BIGMAP_iter it;
for(it=maper.begin();it!=maper.end();++it)
{
cout<<(it->first);//string-type
set<newpair> cyc;
cyc=it->second;//set<newpair>-type
for(SET_pair_ITER iter=cyc.begin();iter!=cyc.end();++iter)
{
newpair ctn=*iter;
cout<<" article "<<ctn.article<<" line "<<ctn.line<<endl;
}
}
return ;
} void buildmaper(string aim,int articlenum,int linenum)
{
newpair m;
m.article=articlenum;
m.line=linenum;
maper[aim].insert(m);
} int readin()
{
int n;
char c;//input the \n
cin>>n>>c;
int cur=;
for(int i=;i<n;cur++)
{
getline(cin,psd[cur]);
if((int)psd[cur].find("***")!=-){i++;continue;}//the next article
for(string::iterator it=psd[cur].begin();it!=psd[cur].end();++it)
{
if(isalpha(*it)) *it=tolower(*it);
else *it=' ';
}
stringstream ss(psd[cur]);
string chr;
while(ss>>chr) buildmaper(chr,i,cur);
}
return cur;
} int main()
{
freopen("input.txt","r",stdin);
freopen("ans.txt","w",stdout);
maxline=readin();
checkmaper();
return ;
}

以上代码涉及了较多C++知识与个别底层知识,下面进行列举:

1、stringstream常用操作

2、基本STL之map与set

3、结构体中的运算符重载

4、迭代器的操作

5、RB树实现map与set的基本原理

有关详细的实现方法请参照我的其它博客和上述代码。

在上述代码中唯一一个容易出现bug的位置是set的实现:由于set对输入的元素需要进行排序,所以必须在newpair结构体中重载<(operator)。

下面是运行图片:

输入如下:

one   repeat  repeat  repeat
A manufacturer, importer, or seller of
digital media devices may not () sell,
or offer for sale, in interstate commerce,
or () cause to be transported in, or in a
manner affecting, interstate commerce,
a digital media device unless the device
includes and utilizes standard security
technologies that adhere to the security
system standards.
**********
one two repeat repeat repeat repeat
Of course, Lisa did not necessarily
intend to read his books. She might
want the computer only to write her
midterm. But Dan knew she came from
a middle-class family and could hardly
afford the tuition, let alone her reading
fees. Books might be the only way she
could graduate
**********
one two three repeat repeat repeat repeat repeat
Research in analysis (i.e., the evaluation
of the strengths and weaknesses of
computer system) is essential to the
development of effective security, both
for works protected by copyright law
and for information in general. Such
research can progress only through the
open publication and exchange of
complete scientific results
**********
one two three four repeat repeat repeat repeat repeat repeat
I am very very very happy!
What about you?
**********

输出如下:

a  article  line
article line
article line
article line
about article line
adhere article line
affecting article line
afford article line
alone article line
am article line
analysis article line
and article line
article line
article line
article line
article line
be article line
article line
books article line
article line
both article line
but article line
by article line
came article line
can article line
cause article line
class article line
commerce article line
article line
complete article line
computer article line
article line
copyright article line
could article line
article line
course article line
dan article line
development article line
device article line
devices article line
did article line
digital article line
article line
e article line
effective article line
essential article line
evaluation article line
exchange article line
family article line
fees article line
for article line
article line
article line
four article line
from article line
general article line
graduate article line
happy article line
hardly article line
her article line
article line 17 其余略。。。。。。。。。。

OK

基于STL的字典生成模块-模拟搜索引擎算法的尝试的更多相关文章

  1. C++ 基于STL的演讲比赛流程管理系统(sort算法+小型算法(accumulate)+内建函数对象+string字符串拼接+字符串截取+多个容器基础操作+与用户交互+文件的读写+保存+重建+整体文件数据的清空)

    1 /* 2 比赛规则: 3 学校举行一演讲比赛,共12个人参加,比赛两轮,第一轮为淘汰赛 第二轮为决赛 4 每名选手都有对应的编号:如10001~10012 5 比赛方式:分组比赛 每组6人 6 第 ...

  2. 基于STL优先队列和邻接表的dijkstra算法

    首先说下STL优先队列的局限性,那就是只提供入队.出队.取得队首元素的值的功能,而dijkstra算法的堆优化需要能够随机访问队列中某个节点(来更新源点节点的最短距离). 看似可以用vector配合m ...

  3. python 基于 wordcloud + jieba + matplotlib 生成词云

    词云 词云是啥?词云突出一个数据可视化,酷炫.以前以为很复杂,不想python已经有成熟的工具来做词云.而我们要做的就是准备关键词数据,挑一款字体,挑一张模板图片,非常非常无脑.准备好了吗,快跟我一起 ...

  4. 基于FPGA的VGA可移植模块终极设计【转】

    本文转载自:http://www.cnblogs.com/lueguo/p/3373643.html 略过天涯   基于FPGA的VGA可移植模块终极设计 一.VGA的诱惑 首先,VGA的驱动,这事, ...

  5. SQL Server2005+、MySQL、Oracle 数据库字典生成工具

    之前找的数据库字典生成工具基本上都依赖于 Office Com 组件,在不安装 Office的情况下无法使用.怒,于是自己用C# 写了一个.     特征如下:         一.支持的数据库 MS ...

  6. [FUZZ]文件上传fuzz字典生成脚本—使用方法

    文件上传fuzz字典生成脚本-使用方法 原作者:c0ny1 项目地址:https://github.com/c0ny1/upload-fuzz-dic-builder 项目预览效果图: 帮助手册: 脚 ...

  7. PJzhang:crunch,一个很好的字典生成工具

    猫宁!!! 之前收集子域名的时候使用过子域名挖掘机这个windows软件,查看了它所使用的字典,基本上是小写字母数字1-4位的一个合集.   36+36*36+36*36*36+36*36*36*36 ...

  8. 文件上传漏洞fuzz字典生成脚本小工具分享

    前言 学习xss的时候翻阅资料发现了一个文件上传漏洞fuzz字典生成脚本小工具,试了试还不错,分享一下 配置 需要python2环境 工具地址:https://github.com/c0ny1/upl ...

  9. 【vue】生成接口模拟数据

    目录 方案一:自定义模拟数据 Step1 创建json文件 Step2 在 vue.config.js 中配置 Step3 在组件中使用 (方式一) Step3 封装api (方式二) Step4 在 ...

随机推荐

  1. shell脚本自动化部署

    由于公司技术部团队较小,没有专门的运维团队,所以运维工作技术部承包了. 一.纯人工部署是这样的: 1. 本地打包:一般 maven clean package 2. 借助xftp上传到服务器对应目录 ...

  2. Decorator - 装饰器

    装饰器 Decorator, 先来看看对 decorator 这个名词的解释, 一个可调用的对象 A (decorator), 返回另一个可调用的对象 B, 在可调用的对象 C 的定义体之前通过语法 ...

  3. Apache开启GZIP 压缩网页

    首先我们先了解Apache Gzip的相关资料. 一.gzip介绍 Gzip是一种流行的文件压缩算法,现在的应用十分广泛,尤其是在Linux平台.当应用Gzip压缩到一个纯文本文件时,效果是非常明显的 ...

  4. k8s集群PHP环境使用

    一.环境介绍 k8s版本: 1.15.2 存储: 阿里云NAS 测试代码: wordpress 二.下载wordpress和创建好数据库等 1.下载wordpress wget https://cn. ...

  5. Android O 8.0 奥利奥

    Android O 8.0 奥利奥 1.画中画, 2.智能文本选择(Smart Text Selection), 3.notification dots, 4.自动填写(Auto-Fill)   4. ...

  6. Java基于过滤器进行重定向不成功问题的兩種解決辦法,以及基於JSF的ajax重定向解決辦法

    我创建了一个过滤器,只要用户没有登陆就不能连接到主界面,但是在doFilter方法中用重定向在前端跳转页面不成功. 原因:由于我的登陆界面是基于ajax请求的,而ajax默认不支持重定向,他只能局部更 ...

  7. Basic Auth攻击

    1.Basic Auth认证简介 Basic身份认证,是HTTP 1.0中引入的认证方案之一.虽然方案比较古老,同时存在安全缺陷,但由于实现简单,至今仍有不少网站在使用它. 例如Apche Tomca ...

  8. 实训第八天 有关python orm 的学习记录 常用方法01

    沿用第七天的数据库,数据库现在是这样的: 配置好主路由include子路由 子路由引入views 在views页面定义test测试请求如下: def test(request): # 1.all()方 ...

  9. toj 3761 Egg Problem (好题~~)

    Egg Problem 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交: 22 测试通过: 7 描述 There is a very interest ...

  10. search(0)- 企业搜索,写在前面

    计划研究一下搜索search,然后写个学习过程系列博客.开动之前先说说学习搜索的目的:不是想开发个什么搜索引擎,而是想用现成的搜索引擎在传统信息系统中引进搜索的概念和方法.对我来说,传统的管理系统le ...