【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

用map >mmap[100];来记录每一个数据段某个字符串出现的行数,以及用来判断这个字符串在这一段中存不存在。
**
->这里有一个地方要注意,千万不要在未确定这个字符串是否存在之前,调用mmap[i][s],因为这样,不管s存不存在,s都会加那么一个键值。
->而这就使得我们不能用更快的mmap[i].find(s)函数来寻找某个字符串在不在了.
->用mmap[i][s]访问,然后判断在不在的方式是会TLE的。
**
样例有9个'-'但实际上输出10个'-';
然后就是各个数据段之间的分隔符的输出。
or和and的输出都要用set来重新排序。
即从小的行开始到大的行依序输出。

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = 100; int n, m;
vector <string> v[N + 10];
set <int> vv;
map <string, vector<int> > mmap[N + 10];
string s, ts; bool have(int idx, string s)
{
if (mmap[idx].find(s)==mmap[idx].end())
return false;
else
return true;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0);
cin >> n; cin.get();
for (int ii = 1; ii <= n; ii++)
{
int tot = 0;
while (getline(cin, s))
{
if (s == "**********") break;
v[ii].push_back(s); int len = s.size();
for (int i = 0; i < len; i++)
if (isalpha(s[i]))
s[i] = tolower(s[i]);
else
s[i] = ' ';
stringstream temp(s);
string x;
while (temp >> x)
{
mmap[ii][x].push_back(tot);
}
tot++;
}
} cin >> m; cin.get();
for (int i = 0; i < m; i++)
{
getline(cin, ts);
int fi = ts.find(' ', 0);
if (fi == -1)//find x
{
bool ok = false;
for (int j = 1; j <= n; j++)
if (have(j, ts))
{
if (ok) cout << "----------" << endl;
ok = true;
vv.clear();
for (int x : mmap[j][ts]) vv.insert(x);
for (int x : vv) cout << v[j][x] << endl;
}
if (!ok) cout << "Sorry, I found nothing." << endl;
cout << "==========" << endl;
}
else
{
int fi2 = ts.find(' ', fi + 1);
if (fi2 == -1)//not x
{
bool ok = false;
ts = ts.substr(fi);
while (ts[0] == ' ') ts.erase(0, 1);
for (int j = 1; j <= n; j++)
if (!have(j, ts))
{
if (ok) cout << "----------" << endl;
ok = true;
int lenv = v[j].size();
for (int k = 0; k < lenv; k++)
cout << v[j][k] << endl;
}
if (!ok) cout << "Sorry, I found nothing." << endl;
cout << "==========" << endl;
}
else // x y z
{
stringstream ss(ts);
string x, y, z;
ss >> x; ss >> y; ss >> z;
if (y == "OR")
{
bool ok = false;
for (int j = 1; j <= n; j++)
if (have(j, x) || have(j, z))
{
if (ok) cout << "----------" << endl;
ok = true;
vv.clear();
if (have(j,x))for (int t : mmap[j][x]) vv.insert(t);
if (have(j,z))for (int t : mmap[j][z]) vv.insert(t);
for (int t : vv) cout << v[j][t] << endl;
}
if (!ok) cout << "Sorry, I found nothing." << endl;
cout << "==========" << endl;
}
else
{
bool ok = false;
for (int j = 1; j <= n; j++)
if (have(j, x) && have(j, z))
{
if (ok) cout << "----------" << endl;
ok = true;
vv.clear();
for (int t : mmap[j][x]) vv.insert(t);
for (int t : mmap[j][z]) vv.insert(t);
for (int t : vv) cout << v[j][t] << endl;
}
if (!ok) cout << "Sorry, I found nothing." << endl;
cout << "==========" << endl;
}
}
}
}
return 0;
}

【习题 5-10 UVA-1597】Searching the Web的更多相关文章

  1. uva 1597 Searching the Web

    The word "search engine" may not be strange to you. Generally speaking, a search engine se ...

  2. [刷题]算法竞赛入门经典(第2版) 5-10/UVa1597 - Searching the Web

    题意:不难理解,照搬题意的解法. 代码:(Accepted,0.190s) //UVa1597 - Searching the Web //#define _XIENAOBAN_ #include&l ...

  3. Searching the Web论文阅读

    Searching the Web   (Arvind Arasu etc.) 1. 概述 2000年,23%网页每天更新,.com域内网页40%每天更新.网页生存半衰期是10天.描述方法可用Pois ...

  4. STL --- UVA 123 Searching Quickly

    UVA - 123 Searching Quickly Problem's Link:   http://acm.hust.edu.cn/vjudge/problem/viewProblem.acti ...

  5. ArcGIS Portal 10.4 本地坐标系的web 3d地形展示制作说明

    原文:ArcGIS Portal 10.4 本地坐标系的web 3d地形展示制作说明 ArcGIS Portal 10.4 本地坐标系的web 3d地形展示制作说明 By 李远祥 ArcGIS Por ...

  6. 10 个基于 jQuery 的 Web 交互插件推荐

    英文原文:10 jQuery for Web Interaction Plugins “用户交互”在现代的 Web 设计中占据了很大比例,这是互联网产品不可或缺的关键,对 Web 设计师也提出了更高的 ...

  7. 10个优秀的移动Web应用开发框架

    在最近几年里,移动互联网高速发展.市场潜力巨大.继计算机.互联网之后,移动互联网正掀起第三次信息技术革命的浪潮,新技术.新应用不断涌现.今天这篇文章向大家推荐10大优秀的移动Web开发框架,帮助开发者 ...

  8. Searching the Web UVA - 1597

      The word "search engine" may not be strange to you. Generally speaking, a search engine ...

  9. Nginx 1.10.2 发布,高性能 Web 服务器

    Nginx 1.10.2 发布了.Nginx(发音同 engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器 更新内容: Changes with n ...

随机推荐

  1. 56.ERR! configure error gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.

    Node.js 在安装模块的时候报错,缺少python环境. ERR! configure error gyp ERR! stack Error: Can't find Python executab ...

  2. 1、Bracket使用

    转自:https://www.jianshu.com/p/393833400782 Adobe的PhotoShop.Dreamweaver等大批优秀软件,印(nue)象(杀)了一代一代的优秀的计算机高 ...

  3. typeof 和 instanceof 的区别

    在JavaScript中我们想得到一个变量的类型,我们一般会用typeof 得到这个类型的 字符串,但是对于引用类型,typeof始终会返回一个"object",在我们js中有十个 ...

  4. Day1下午解题报告

    预计分数:0+30+30=60 实际分数:0+30+40=70 T1水题(water) 贪心,按长度排序, 对于第一幅牌里面的,在第二个里面,找一个长度小于,高度最接近的牌 进行覆盖. 考场上的我离正 ...

  5. Repeater控件的

    http://blog.csdn.net/zhang_xinxiu/article/details/21872433 想起来,公司的aspx页面前台数据展示除了datagrid以为还有Repeater ...

  6. 如何监控和解决SQL Server的阻塞(1) (当前阻塞)

    1. 什么是"阻塞"? 阻塞是SQL数据库应用"锁"机制的一个副作用.当一个应用请求针对某个数据库对象(例如全表,某行数据, 或者是某个数据页)加锁后,那么这个 ...

  7. thuwc9102划水记

    thuwc9102划水记 Day -2 时隔两个月之后终于回一次家,心情非常愉悦,开始浪. Day 0 晚上回到学校,然而机房里并没多少人,大佬们明天才回来.╮(╯▽╰)╭ Day 1 中午饭菜挺好吃 ...

  8. ActiveMQ学习总结(2)——ActiveMQ入门实例教程

    1.下载ActiveMQ 去官方网站下载:http://activemq.apache.org/ 2.运行ActiveMQ 解压缩apache-activemq-5.5.1-bin.zip,然后双击a ...

  9. Android 关于expandableListView childrenView 点击改变颜色

    1.点击后改变颜色并保持颜色改变状态: <?xml version="1.0" encoding="utf-8"?> <selector xm ...

  10. Android 阅读器架构图,网上收集,留做存货

    这个结构图是网上收集的图片.基结构明晰简洁.易于后期维护.本文会继续收集很多其他其他优秀的结构图,望有图的朋友推荐~