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

【题意】

在这里输入题意

【题解】

用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. 浏览器加载渲染HTML、DOM、CSS、 JAVASCRIPT、IMAGE、FLASH、IFRAME、SRC属性等资源的顺序总结

    页面响应加载的顺序:   1.域名解析->加载html->加载js和css->加载图片等其他信息 DOM详细的步骤如下: 解析HTML结构. 加载外部脚本和样式表文件. 解析并执行脚 ...

  2. POJ 2138 最长路

    思路: 如果j能由i得到 则i向j连一条边 答案就是最长路的末节点所代表的string //By SiriusRen #include <cstdio> #include <cstr ...

  3. 洛谷P2891 [USACO07OPEN]吃饭Dining

    题目描述 Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she w ...

  4. Gym 100952 G. The jar of divisors

    http://codeforces.com/gym/100952/problem/G G. The jar of divisors time limit per test 2 seconds memo ...

  5. java高质量缩放图片

    可按照比例缩放,也可以指定宽高 import com.sun.image.codec.jpeg.JPEGImageEncoder; import com.sun.image.codec.jpeg.JP ...

  6. angularjs之ui-bootstrap的Datepicker Popup不使用JS实现双日期选择控件

    最开始使用ui-bootstrap的Datepicker Popup日期选择插件实现双日期选择时间范围时,在网上搜了一些通过JS去实现的方法,不过后来发现可以不必通过JS去处理,只需要使用其自身的属性 ...

  7. nohup---将程序以忽略挂起信号的方式运行起来

    nohup nohup命令:如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么可以使用nohup命令.该命令可以在你退出帐户/关闭终端之后继续运行相应的进程. 在缺省情况下该作业的所 ...

  8. 软考之路--从生活着手,看PV怎样操作

    PV操作.是软考其中一个非常重要的考点,一听到这个名词,顿时赶脚高大上有么有,在软考的历年试题中,也不乏PV操作的身影,老师也对PV操作进行了一次讲课,那时年少.听得稀里糊涂,也不是非常理解,在小编的 ...

  9. iOS报错 -pie can only be used when targeting iOS 4.2 or later

    近期,使用师兄的project时.突然报错之前没发现这个错误.信息例如以下: ld: -pie can only be used when targeting iOS 4.2 or later cla ...

  10. 用 runcloud.io 免费部署、优化管理你的多个VPS( 目前支持 Ubuntu 16.04 )

    使用RunCloud.io轻松实现Web部署 使用VPS.云服务器,通常会安装基本的操作系统,之后必须自己安装Apache,MySQL,PHP,尤其是服务器的性能优化,这对大多数人来说可能是非常具有挑 ...