Hotel
2016-07-21 20:22
246 查看
Hotel
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
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?
Input
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.
Output
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.
Sample Input
herbert
2
amazon
herbert
?ert*
2
amazon
herbert
*
2
amazon
anything
herbert?
2
amazon
herber
Sample Output
1
0
2
0
View Code
递归函数。
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
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?
Input
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.
Output
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.
Sample Input
herbert
2
amazon
herbert
?ert*
2
amazon
herbert
*
2
amazon
anything
herbert?
2
amazon
herber
Sample Output
1
0
2
0
#include<iostream> #include<stdio.h> #include<string.h> #include<string> using namespace std; bool pipei(string a,string b){ for(int i=0;i<a.length();i++){ if(a[i]=='*'){ if(i==a.length()-1) return true; string c= a.substr(i+1); for(int j=i;j<b.length();j++){ if(pipei(c,b.substr(j))) return true; } }else{ if(i>=b.length()) return false;if(a[i]=='?') continue; if(a[i]!=b[i]) return false; } } return true; } int main(){ string a,b; while(cin>>a){ int n; int ans=0; scanf("%d",&n); for(int i=0;i<n;i++){ cin>>b; if(pipei(a,b)){ ans++; } } printf("%d\n",ans); } return 0; }
View Code
递归函数。
相关文章推荐
- Notification
- NYOJ 330 一个简单的数学题【思维】
- HDU 1241 Oil Deposits 油田 搜索
- Restaurant
- Hibernate中,One2Many和Many2One的双向映射关系的XML实现方式
- 用slf4j+logback实现多功能日志解决方案 --- 转
- linker command failed with exit code 1 (use -v to see invocation)
- linker command failed with exit code 1 (use -v to see invocation)
- HDU 4268-Alice and Bob-贪心
- ifconfig command not found
- 告诉你一个java对象占用的内存大小的方法
- 引用传递&值传递
- 项目打包版本号维护
- 一个二分类的例子
- MySQL学习笔记(四)—存储过程
- 软件悬浮窗的隐藏
- 【转载】.NET程序员走向高端必读书单汇总
- 树形DP——Party a Haili-Bula ( HDU 3342 )
- UVA - 10499 The Land of Justice
- 【CodeForces】612A - The Text Splitting(枚举)