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

【递推】【HDU2585】【hotel】的更多相关文章

  1. 【BZOJ-2476】战场的数目 矩阵乘法 + 递推

    2476: 战场的数目 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 58  Solved: 38[Submit][Status][Discuss] D ...

  2. 从一道NOI练习题说递推和递归

    一.递推: 所谓递推,简单理解就是推导数列的通项公式.先举一个简单的例子(另一个NOI练习题,但不是这次要解的问题): 楼梯有n(100 > n > 0)阶台阶,上楼时可以一步上1阶,也可 ...

  3. Flags-Ural1225简单递推

    Time limit: 1.0 second Memory limit: 64 MB On the Day of the Flag of Russia a shop-owner decided to ...

  4. 利用Cayley-Hamilton theorem 优化矩阵线性递推

    平时有关线性递推的题,很多都可以利用矩阵乘法来解决. 时间复杂度一般是O(K3logn)因此对矩阵的规模限制比较大. 下面介绍一种利用利用Cayley-Hamilton theorem加速矩阵乘法的方 ...

  5. 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】

    还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...

  6. 简单递推 HDU-2108

    要成为一个ACMer,就是要不断学习,不断刷题...最近写了一些递推,发现递推规律还是挺明显的,最简单的斐波那契函数(爬楼梯问题),这个大家应该都会,看一点稍微进阶了一点的,不是简单的v[i] = v ...

  7. [ACM_动态规划] 数字三角形(数塔)_递推_记忆化搜索

    1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> ...

  8. 矩阵乘法&矩阵快速幂&矩阵快速幂解决线性递推式

    矩阵乘法,顾名思义矩阵与矩阵相乘, 两矩阵可相乘的前提:第一个矩阵的行与第二个矩阵的列相等 相乘原则: a b     *     A B   =   a*A+b*C  a*c+b*D c d     ...

  9. openjudge1768 最大子矩阵[二维前缀和or递推|DP]

    总时间限制:  1000ms 内存限制:  65536kB 描述 已知矩阵的大小定义为矩阵中所有元素的和.给定一个矩阵,你的任务是找到最大的非空(大小至少是1 * 1)子矩阵. 比如,如下4 * 4的 ...

  10. 02python算法-递推

    递推 1什么是递推?:根据已有节点的值,以及规律推出之后节点的值 2为什么要用递推:简单的解决有规矩事件 3怎么用?: 我们举个经典的例子: 如果1对兔子每月能生1对小兔子,而每对小兔在它出生后的第3 ...

随机推荐

  1. Js 中常用方法

    一.获取唯一值(2014-12-23) function newGuid() { var guid = ""; var n = (((1 + Math.random()) * 0x ...

  2. java面试题集1

    一:单选题 下列哪一种叙述是正确的(D )A. abstract修饰符可修饰字段.方法和类B. 抽象方法的body部分必须用一对大括号{ }包住C. 声明抽象方法,大括号可有可无D. 声明抽象方法不可 ...

  3. 出现security ioError 安全沙箱问题

    client安全沙箱 通配策略 crossdomain <?xml version="1.0" encoding="UTF-8"?> <!DO ...

  4. Reflux 使用教程

    Reflux是根据React的flux创建的单向数据流类库.Reflux的单向数据流模式主要由actions和stores组成.例如,当组件list新增item时,会调用actions的某个方法(如a ...

  5. javascript 命名空间,学习

    一. (function(){ var _NS=function(){ } _NS.prototype.alert=function(){ console.log('test'); } window. ...

  6. AspnetPager放在UpdatePanel中,回到顶部。

    最近在做一个项目时,使用了AspNetPager分页控件进行分页,为了防止点击下一页时搜索条件消失掉,使用了UpdatePanel来进行局部刷新. 由此引发了一个问题,即点击某一页时,页面没有返回到顶 ...

  7. 利用cookie改变背景色

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Linked List Cycle (java)

    public boolean hasCycle(ListNode head) { ListNode slow=head; ListNode fast=head; if(head==null)retur ...

  9. Fedora下用Iptux,中文乱码解决

    Ubuntu/Fedora下用Iptux与Windows下大飞鸽传书,中文乱码解决 问题描述: 在Ubuntu/Fedora下安装了Iptux后,再往Windows机器上发送文件或消息时,如果有中文, ...

  10. Servlet开发(一)

    一.Servlet简介 Servlet是sun公司提供的用于开发动态web资源的技术.Sun公司在其API中提供了一个Servlet接口,用户若想开发一个动态web资源(即开发一个java程序向浏览器 ...