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
 
字符串的模糊匹配,?可以当做都匹配的一个字符,遇到*时自带一个查找
 
 #include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string> using namespace std; char a[],b[];
int n,len1,len2,res; bool digital(int i,int j)
{
//结尾判定
if(i==len1&&j==len2)
return true;
else if(i==len1||j==len2)
return false;
//中间过程
else if(a[i]=='*')
{
for(int k=j;k<=len2;k++)
if(digital(i+,k))
return true;
}
else if(a[i]=='?'||a[i]==b[j])
digital(i+,j+);
else
return false;
} int main()
{
while(scanf("%s",&a)!=EOF)
{
scanf("%d\n",&n);
len1=strlen(a);
res=;
while(n--)
{
scanf("%s",&b);
len2=strlen(b);
if(digital(,))
res++;
}
printf("%d\n",res);
}
return ;
}

HDU 2585 Hotel(字符串的模糊匹配+递归)的更多相关文章

  1. HDU 2585 [Hotel]字符串递归处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2585 题目大意:马克思要找个曾经去过的很好的旅馆,可惜他记不完整旅馆的名字.他有已知的部分信息和可能的 ...

  2. HDU 1274 展开字符串 (递归+string类)

    题目链接:HDU 1274 展开字符串 中文题. 左括号进入DFS函数,右括号return到上一层. 注意return回去的是这个一层递归中的括号中的字母串. AC代码: #include<st ...

  3. C++实现的字符串模糊匹配

    C++基本没有正则表达式功能,当然像Boost里提供了正则.本文来源于博客园园友的一篇文章,请看: C/C++ 字符串模糊匹配 很早之前就看过这篇文章,原作者的需求很明确.代码实现也很好. 之所以又写 ...

  4. mysql 两张表字段模糊匹配--字符串拼接函数

    concat(A,B,C,...)  拼接字符串 例如concat('123','***','345')  =>123***345 SELECT concat( substr(t1.CODE, ...

  5. 简单易用的字符串模糊匹配库Fuzzywuzzy

    简单易用的字符串模糊匹配库Fuzzywuzzy 阅读目录 FuzzyWuzzy 简介 安装 用法 已知移植 FuzzyWuzzy 简介 FuzzyWuzzy 是一个简单易用的模糊字符串匹配工具包.它依 ...

  6. dev 中 字符串转中文拼音缩写,对grid列表进行模糊匹配,grid获取焦点行,gridlookupedit控件用拼音模糊匹配下拉选项

    番外篇:. //该方法是将字符串转化为中文拼音的首写字母大写, public static string RemoveSpecialCharacters(string str){try{if (str ...

  7. 使用vlookup的模糊匹配和字符串拼接

    1,=IF(ISNA(VLOOKUP("*"&$D2&"*",$A$2:$A$43,1,FALSE))=FALSE,TRUE,FALSE) 2, ...

  8. sql模糊匹配中%、_的处理

    防sql注入之模糊匹配中%._处理: StringBuilder sbSql = new StringBuilder(); sbSql.Append(@"SELECT * from tabl ...

  9. Mysql 模糊匹配和转义字符

    首先创建一个测试表: insert into test(tt) values('\\\\172.18.28.153'); 现在我想使用模糊匹配,查出以 “\\172” 开头的字符串. 需要使用like ...

随机推荐

  1. leetcode-algorithms-34 Find First and Last Position of Element in Sorted Array

    leetcode-algorithms-34 Find First and Last Position of Element in Sorted Array Given an array of int ...

  2. 深入Spring Boot: 怎样排查 java.lang.ArrayStoreException

    java.lang.ArrayStoreException 分析 这个demo来说明怎样排查一个spring boot 1应用升级到spring boot 2时可能出现的java.lang.Array ...

  3. 浏览器行为模拟之requests、selenium模块

    requests模块 前言: 通常我们利用Python写一些WEB程序.webAPI部署在服务端,让客户端request,我们作为服务器端response数据: 但也可以反主为客利用Python的re ...

  4. Django之cookie+session

    前言 HTTP协议 是短连接.且状态的,所以在客户端向服务端发起请求后,服务端在响应头 加入cokie响应给浏览器,以此记录客户端状态: cook是来自服务端,保存在浏览器的键值对,主要应用于用户登录 ...

  5. [LeetCode] 94. Binary Tree Inorder Traversal(二叉树的中序遍历) ☆☆☆

    二叉树遍历(前序.中序.后序.层次.深度优先.广度优先遍历) 描述 解析 递归方案 很简单,先左孩子,输出根,再右孩子. 非递归方案 因为访问左孩子后要访问右孩子,所以需要栈这样的数据结构. 1.指针 ...

  6. windows启动/禁用telnet/IIS/ftp/IE等服务

    将需要启动的钩选,将要禁用的取消钩选确定即可:比如我这里要启动telnet客户端. 启动IIS将IIS可承载的Web核心和Internet两大项全钩选上即可,钩多了不影响功能.

  7. Linux变量及运算

    变量赋值:var=var_value 变量引用:$var 算术运算:var=`expr $var1 + $var2` 字符串连接:var=str$var1 数值比较:-eq/-ne/-gt/-lt/- ...

  8. 牛客网 PAT 算法历年真题 1002 :数字分类 (20)

    1002 :数字分类 (20) 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 给定一系列正整数,请按要求对数字 ...

  9. asp企业网站源码部分

    ASP的网页文件的格式是.asp,现在常用于各种动态网站中.PHP是一种 HTML 内嵌式的语言,PHP与微软的ASP颇有几分相似,都是一种在服务器端执行的嵌入HTML文档的脚本语言,语言的风格有类似 ...

  10. CentOS查询系统版本

    1.cat /proc/version 2.cat /etc/redhat-release 3.cat /proc/version 4.uname -a