HDU2532 Engine 字符串+模拟

来源:互联网 发布:陕西大数据集团怎么样 编辑:程序博客网 时间:2024/05/22 06:44

1.题目描述:

Engine

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 593    Accepted Submission(s): 137


Problem Description
谷歌、百度等搜索引擎已经成为了互连网中不可或缺的一部分。在本题中,你的任务也是设计一个搜索论文的搜索引擎,当然,本题的要求比起实际的需求要少了许多。
本题的输入将首先给出一系列的论文,对于每篇论文首先给出标题,然后给出它被引用的次数。然后会有一系列的搜索询问,询问标题中包含特定关键词的论文有哪些。
每一个询问可能包含多个关键词,你需要找出标题包含所有关键词的论文。
“包含”必须是标题中有一个词正好是给定的关键词,不区分大小写。
对每个询问,都按被引用的次数从多到少输出满足条件的论文的标题。如果有被引用的次数相同的论文,则按照论文在输入中的顺序排列,先给出的论文排在前面。

 

Input
输入包含多组数据。
每组数据首先有一行包含一个整数N(1<=N<=1000),表示论文的数目,N=0表示输入结束。每组论文的信息第一行是论文的标题,由字母(大小写均可)和空格组成,不超过10个词,每个词不超过20个字符,标题总共不超过250个字符。第二行是一个整数K(0<=K<=108),表示它被引用的次数。在论文信息结束以后,有一行包含一个整数M(1<=M<=100),表示询问的数目。接下来有M行,每行是一个询问,由L(1<=L<=10)个空格分开的词构成,每个词不超过20个字符。

 

Output
对每个询问,按照题目给定的顺序输出满足条件的论文的标题;如果没有满足条件的论文,就不输出。在每组询问的输出之后输出一行”***”,在每组数据的输出之后输出一行”---”。
 

Sample Input
6Finding the Shortest Path120Finding the k Shortest Path80Find Augmenting Path in General Graph80Matching in Bipartite Graph200Finding kth Shortest Path50Graph Theory and its Applications406shortest pathk shortest pathgraphpathfindapplication0
 

Sample Output
Finding the Shortest PathFinding the k Shortest PathFinding kth Shortest Path***Finding the k Shortest Path***Matching in Bipartite GraphFind Augmenting Path in General GraphGraph Theory and its Applications***Finding the Shortest PathFinding the k Shortest Path Find Augmenting Path in General GraphFinding kth Shortest Path***Find Augmenting Path in General Graph******---
 

Source
The 6th UESTC Programming Contest
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  2528 2529 2530 2531 2533 
3.解题思路:

就是一道简单模拟,然而wa了很久orz,希望以后多查错,多码

4.WA代码

#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;struct node// 标题{char title[300];int vis;int id;}num[1010];struct node1 // 存放查询的所有单词{char ch[30];int len;}re[15];struct node2 // 存放每一句里面的单词{char ch[30];int len;}word[15];int cmp(node a, node b){if (a.vis == b.vis)return a.id < b.id;return a.vis > b.vis;}char lowchar(char ch){if (ch < 'a')return ch + 32;return ch;}int main(){int n, m;while (scanf("%d", &n) != EOF && n){memset(num, 0, sizeof(num));getchar();for (int i = 0; i < n; i++){gets(num[i].title);scanf("%d", &num[i].vis);getchar();num[i].id = i;}sort(num, num + n, cmp);scanf("%d", &m);char rech[300];getchar();while (m--){memset(word, 0, sizeof(word));memset(rech, 0, sizeof(rech));gets(rech);int cnt = 0;int len = strlen(rech);int sta = 0;for (int p = 0; p <= len; p++)if (rech[p] == ' ' || rech[p] == '\0'){for (int i = sta; i < p; i++)word[cnt].ch[i - sta] = lowchar(rech[i]);word[cnt++].len = p - sta;sta = p + 1;}for (int i = 0; i < n; i++){int cnt1 = 0;memset(re, 0, sizeof(re));int len = strlen(num[i].title);int sta = 0;for (int p = 0; p <= len; p++)if (num[i].title[p] == ' ' || num[i].title[p] == '\0'){for (int j = sta; j < p; j++)re[cnt1].ch[j - sta] = lowchar(num[i].title[j]);re[cnt1++].len = p - sta;sta = p + 1;}/*judge*/int ans = 0;for (int j = 0; j < cnt; j++)// 对查询的每个单词{for (int k = 0; k < cnt1; k++){if (word[j].len != re[k].len)continue;if (strcmp(word[j].ch, re[k].ch) == 0)ans++;}}if (ans == cnt)printf("%s\n", num[i].title);}printf("***\n");}printf("---\n");}    return 0;}


0 1
原创粉丝点击