Uva - 1597 - Searching the Web
来源:互联网 发布:淘宝节点考试助手2017 编辑:程序博客网 时间:2024/06/10 21:59
早晨写了好久,最后终于AC了,有一定的实际问题意义。
AC代码:
注意提交的时候选C++11,如果选C++会CE。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cctype>#include <cstring>#include <string>#include <sstream>#include <vector>#include <set>#include <map>#include <algorithm>#include <stack>#include <queue>#include <bitset> #include <cassert> using namespace std;#define rep(i, b) for(int i = 0; i < (b); i++)#define FOR for(int j = limitLine[i]; j < limitLine[i + 1]; j++)typedef bool Bit[1505];int n, lines, m; // n文档数,lines行数,m请求数int limitLine[105]; // limit[i]:第i篇文档从第几行开始string doc[1505]; // 文章内容map<string, Bit> Index; // Index[单词]:Bit标记了哪些行出现过// 用s来更新Indexvoid upDate(string s, int p){string word;for (string::iterator it = s.begin(); it != s.end(); it++) {if (isalpha(*it)) {*it = tolower(*it); // 所有字母都转换成小写}else {*it = ' '; // 非字符变空白}}stringstream ss(s);while (ss >> word) {Index[word][p] = true;}}int main(){//ios::sync_with_stdio(false);//cin >> n;scanf("%d ", &n);rep(i, n) {limitLine[i] = lines;while (getline(cin, doc[lines]), doc[lines] != "**********") {upDate(doc[lines], lines);lines++;}}limitLine[n] = lines;string s;Bit mark;bool *A, *B;scanf("%d ", &m);for (int iii = 0; iii < m; iii++) {getline(cin, s);if (s[0] == 'N') {A = Index[s.substr(4)];rep(i, n) {bool logo = true;FOR if (A[j]) {logo = false;break;}FOR mark[j] = logo;}}else if (s.find("AND") != string::npos) {int p = s.find(" AND ");A = Index[s.substr(0, p)];B = Index[s.substr(p + 5)];memset(mark, 0, sizeof(mark));bool hasA, hasB; // 在同一文章中,两个词是否都出现rep(i, n) {hasA = hasB = false;FOR if (A[j]) {hasA = true;break;}FOR if (B[j]) {hasB = true;break;}if (!(hasA && hasB)) {continue;}FOR mark[j] = (A[j] || B[j]);}}else if (s.find("OR") != string::npos) {int p = s.find(" OR ");A = Index[s.substr(0, p)];B = Index[s.substr(p + 4)];rep(i, lines) mark[i] = (A[i] || B[i]);}else {memcpy(mark, Index[s], sizeof(mark));}// 输出markbool hasOut = false, needOut = false;rep(i, n) {if (hasOut) needOut = true;hasOut = false;FOR if (mark[j]) {if (needOut) {cout << "----------\n";needOut = false;}cout << doc[j] << endl;hasOut = true;}}if (!(needOut || hasOut)) {cout << "Sorry, I found nothing.\n";}cout << "==========\n";}return 0;}
0 0
- UVa 1597-Searching the Web
- UVa 1597 - Searching the Web
- UVa:1597 - Searching the Web
- Uva - 1597 - Searching the Web
- UVa 1597 - Searching the Web(模拟)
- uva 1597 Searching the Web (wrong)
- 1597 - Searching the Web
- 5-10 UVA 1597 Searching the Web在Web中搜索
- searching the Deep web
- UVa1597 Searching the Web
- UVa1597 - Searching the Web
- Uva1597 -Searching the Web
- 《searching the web》学习笔记
- POJ 2050 Searching the Web
- UVA 1597 Search the Web
- 搜索引擎早期重要论文推荐系列【7】《Searching the Web》
- UVa 123 Searching Quickly
- uva 123 Searching Quickly
- 北大ACM1007——DNA Sorting
- 欢迎使用CSDN-markdown编辑器
- Anagrams
- PHP通过Thrift操作Hbase
- PB11.5上开发B/S需要预装哪些软件?
- Uva - 1597 - Searching the Web
- 九章算法面试题74 中位数
- Effective C++条款04解读:确定对象被使用之前已先被初始化
- Distinct Subsequences
- Python 各种IDE比较
- js正则表达式之exec方法讲解
- 寻找最给力的恢复软件(数据恢复软件大PK)数据恢复软件测评报告:
- 数据结构实验:连通分量个数
- 九章算法面试题75 二叉树的最小深度