Hotel

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 277    Accepted Submission(s): 161

Problem 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
 

很好的一个实际中可能出现的问题 关于通配符的

如果利用普通的字符串处理

*a

1

baa

这种数据十分难处理 不知道a 匹配前一个还是后一个

所以要用递归的方式

#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;
}

最新文章

  1. Web Uploader - 功能齐全,完美兼容 IE 的上传组件
  2. pmap
  3. js递归
  4. Visual studio 非常好的插件
  5. 每天一个linux命令(40):watch命令
  6. DROP TABLE ** CASCADE CONSTRAINTS PURGE删除表的时候级联删除从表外键
  7. SQL 查询CET使用领悟
  8. http://blog.csdn.net/jiazimo/article/details/17265061
  9. [SAP ABAP开发技术总结]物料、生产、采购、销售长文本
  10. hdu----(1847)Good Luck in CET-4 Everybody!(简单巴什博奕)
  11. MFC应用程序的开发流程
  12. 秋叶PPT-三分钟教程
  13. Linux学习之十五、基础正规表示法\延伸正规表示法
  14. Python开发环境Spyder安装方法
  15. 初识Dubbo 系列之4-Dubbo 依赖
  16. EditTex属性
  17. 一个简单易懂的javascrip selection&amp;range小案例
  18. node async基础1
  19. 【数据结构】B-Tree, B+Tree, B*树介绍
  20. java笔记----property文件读写

热门文章

  1. python之路-SQLAlchemy
  2. quick-cocos2d-x android返回键监听并实现原生退出对话框
  3. SSCTF Final PWN
  4. smaba服务的搭建
  5. android 补间动画
  6. iframe 重新加载闪过白块问题
  7. JQ动画,背景透明度
  8. Citrix 服务器虚拟化之十一 Xenserver管理vApps
  9. plsql基本语法(
  10. 初识HTML5