HDU 2585 Hotel(字符串的模糊匹配+递归)
2017-07-10 11:11
435 查看
[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
启发博客:http://blog.csdn.net/light_14/article/details/43940765
字符串的模糊匹配,?可以当做都匹配的一个字符,遇到*时自带一个查找
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
启发博客:http://blog.csdn.net/light_14/article/details/43940765
字符串的模糊匹配,?可以当做都匹配的一个字符,遇到*时自带一个查找
#include <iostream> #include<cstdio> #include<cmath> #include<cstring> #include<string> using namespace std; char a[55],b[55]; 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+1,k)) return true; } else if(a[i]=='?'||a[i]==b[j]) digital(i+1,j+1); else return false; } int main() { while(scanf("%s",&a)!=EOF) { scanf("%d\n",&n); len1=strlen(a); res=0; while(n--) { scanf("%s",&b); len2=strlen(b); if(digital(0,0)) res++; } printf("%d\n",res); } return 0; }
相关文章推荐
- 字符串模糊匹配使用递归实现
- 字符串模糊匹配递归实现优化1
- Hdu_2585 Hotel(递归)
- hdu 2585 Hotel 很好的递归模拟题
- C++实现的字符串模糊匹配
- HDU 3336 Count the string 查找匹配字符串
- sql中生成查询的模糊匹配字符串
- C++实现的字符串模糊匹配
- Google字符串模糊匹配算法,字典树模糊查询
- C/C++ 字符串模糊匹配
- C/C++ 字符串模糊匹配
- hdu 4850 字符串构造---欧拉回路构造序列 递归+非递归实现
- hdu 3065 病毒侵袭持续中 DFA 求字符串最多匹配多少字符串 每个子串最多匹配多少个
- 生成查询的模糊匹配字符串.sql
- 生成查询的模糊匹配字符串.sql
- Google字符串模糊匹配算法,字典树模糊查询
- hdu 2222Keywords Search DFA 求字符串最多匹配多少字符串
- 中文字符串模糊匹配算法|C# Levenshtein Distance
- 1197. Hotel (dp,字符串模糊匹配)
- 字符串模糊匹配