hdu 2585 Hotel 很好的递归模拟题
2013-06-05 13:40
344 查看
Hotel
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 216 Accepted Submission(s): 128
[align=left]Problem Description[/align]
Last year summer Max traveled to California for his vacation. He had a great time there: took many photos, visited famous universities, enjoyed beautiful beaches and tasted various delicious foods. It is such a good trip that Max
plans to travel there one more time this year. Max is satisfied with the accommodation of the hotel he booked last year but he lost the card of that hotel and can not remember quite clearly what its name is. So Max searched
in the web for the information of hotels in California ans got piles of choice. Could you help Max pick out those that might be the right hotel?
[align=left]Input[/align]
Input may consist of several test data sets. For each data set, it can be format as below: For the first line, there is one string consisting of '*','?'and 'a'-'z'characters.This string represents the hotel name that Max can remember.The
'*'and '?'is wildcard characters. '*' matches zero or more lowercase character (s),and '?'matches only one lowercase character.
In the next line there is one integer n(1<=n<=300)representing the number of hotel Max found ,and then n lines follow.Each line contains one string of lowercase character(s),the name of the hotel.
The length of every string doesn't exceed 50.
[align=left]Output[/align]
For each test set. just simply one integer in a line telling the number of hotel in the list whose matches the one Max remembered.
[align=left]Sample Input[/align]
herbert
2
amazon
herbert
?ert*
2
amazon
herbert
*
2
amazon
anything
herbert?
2
amazon
herber
[align=left]Sample Output[/align]
1
0
2
0
[align=left]Source[/align]
ECJTU 2009 Spring Contest
[align=left]Recommend[/align]
lcy
http://acm.hdu.edu.cn/showproblem.php?pid=2585
意义: 输入一个串 包含 * ? 和小写字母 其中 *代码任意0个或多个字符 ?代表任意一个字符
然后输入k 之后k个字符串 问这k个字符串中有多少个符合上面的串的格式的
思路:
由于除了* 其他的符号进行比较时都可以一步一步的向后移动 所以遇到*的时候把主串*号之后的 与 现查找串对应位置的所有前缀子串进行比较 只要有一个可以表示成功 则总的来说是可以表示成功的
限于表达能力 直接看代码好一些
#include<stdio.h> #include<iostream> #include<string> using namespace std; int find(string a,string b) { int i,j; for(i=0;i<a.length();i++) { if(a[i]=='*') { if(i==a.length()-1) return true; string c=a.substr(i+1); for(j=i;j<b.length();j++) if(find(c,b.substr(j))) return 1; } else { if(i>=b.length()) return 0; if(a[i]=='?') continue; if(a[i]!=b[i]) return 0; } } return 1; } int main() { int ans; string a,b; while(cin>>a) { int k; ans=0; scanf("%d",&k); while(k--) { cin>>b; if(find(a,b)) ans+=1; } printf("%d\n",ans); } return 0; }
思路主要来自于http://2225377fjs.blog.163.com/blog/static/17462983720111277324151/
fjs的博客 自己要努力额!!!
相关文章推荐
- HDU 2585 Hotel(字符串的模糊匹配+递归)
- Hdu_2585 Hotel(递归)
- HDU 2585 Hotel
- HDU 3887 Counting Offspring dfs序的运用 | 非递归
- [HDU] 4512 吉哥系列故事——完美队形I(有点dp味道的递归模拟)
- hdu 1861 游船出租(模拟题,,水)
- poj3080 很好的字符串模拟题
- 树的非递归遍历:一种很好的算法
- HDU 5694——BD String——————【递归求解】
- HDU 3640【非常复杂模拟题+二分】
- hdu1107武术(模拟题)
- HDU 1084 What Is Your Grade? (模拟题)
- HDU 4930 Fighting the Landlords(扯淡模拟题)
- HDU 1337 The Drunk Jailer--(模拟题找规律)
- HDU-3193 Find the hotel
- hdu 2511 汉诺塔 X 递归 构造
- HDU---Children's queue(递归解法)
- hdu 5339 递归枚举
- hdu 2510 符号三角形 很好的搜索题 要经常看
- hdu 1254 推箱子 很好的嵌套搜索 双层BFS