Two strings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 485    Accepted Submission(s): 178

Problem Description
Giving two strings and you should judge if they are matched.
The first string contains lowercase letters and uppercase letters.
The second string contains lowercase letters, uppercase letters, and special symbols: “.” and “*”.
. can match any letter, and * means the front character can appear any times. For example, “a.b” can match “acb” or “abb”, “a*” can match “a”, “aa” and even empty string. ( “*” will not appear in the front of the string, and there will not be two consecutive “*”.
 
Input
The first line contains an integer T implying the number of test cases. (T≤15)
For each test case, there are two lines implying the two strings (The length of the two strings is less than 2500).
 
Output
For each test case, print “yes” if the two strings are matched, otherwise print “no”.
 
Sample Input
3
aa
a*
abb
a.*
abb
aab
 
Sample Output
yes
yes
no
 
Source
 千千详细分析

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
#define PI acos(-1.0)
int t;
char a[],b[];
int dp[][];
int main()
{
scanf("%d",&t);
while(t--){
scanf("%s",a+);
scanf("%s",b+);
memset(dp,,sizeof(dp));
int lena=strlen(a+);
int lenb=strlen(b+);
dp[][]=;
for(int i=;i<=lenb;i++){
if(i==&&b[i]=='*')
dp[i][]=;
for(int j=;j<=lena;j++){
if(b[i]=='.'||b[i]==a[j])
dp[i][j]=dp[i-][j-];
else if(b[i]=='*'){
dp[i][j]=dp[i-][j]|dp[i-][j];
if((dp[i-][j-]||dp[i][j-])&&a[j-]==a[j])
dp[i][j]=;
}
}
}
if(dp[lenb][lena]==)
printf("yes\n");
else
printf("no\n");
}
return ;
}

最新文章

  1. Power BI for Office 365(五)Power View第二部分
  2. PhoneGap介绍及简单部署
  3. spring security remember me实现自动登录
  4. Spring AOP 简单理解
  5. URL和搜索引擎优化
  6. c#读properties文件
  7. angular 服务
  8. 使用VisualStudio2010创建C#应用程序
  9. android ksoap2调用.net Webservice 方法总结
  10. Java课程设计报告——学生成绩管理系统
  11. [Swift]LeetCode383. 赎金信 | Ransom Note
  12. Python面试真题第三节
  13. LVS负载均衡集群
  14. 201621123002《JAVA程序设计》第十四周学习总结
  15. MATLAB:图像的与、或、非、异或逻辑运算(&amp;、|、~、xor)
  16. HDU - 3006 The Number of set(状态压缩位运算)
  17. gperftools 使用经验总结
  18. 去除android手机浏览器中, 按住链接出现border的情况
  19. 谷歌大脑科学家 Caffe缔造者 贾扬清 微信讲座完整版
  20. spring-cloud服务器雪崩效应

热门文章

  1. [CF963E]Circles of Waiting[高斯消元网格图优化+期望]
  2. webVR全景图多种方案实现(pannellum,aframe,Krpano,three,jquery-vrview)
  3. 10、Dockerfile实战-PHP
  4. git 报错 error: insufficient permission for adding an object to repository database ./objects
  5. CentOS 6.8 安装Tomcat7
  6. 关于几个vcenter的合并心得!
  7. SCRUM 12.09 软件工程第二周计划
  8. linux内核分析第五周学习笔记
  9. Day Two
  10. ElasticSearch搜索实例含高亮显示及搜索的特殊字符过滤