HDU 6170 Two strings
来源:互联网 发布:增值税发票认证软件 编辑:程序博客网 时间:2024/05/18 16:14
Two strings
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 878 Accepted Submission(s): 353
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 “*”.
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).
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
3aaa*abba.*abbaab
Sample Output
yesyesno
Source
2017 Multi-University Training Contest - Team 9
题意:
有两个字符串,问你第二个字符串和第一个字符串能否匹配,第二个字符串有两种符号,
’.’可以匹配任意字符,’*’表示前一个字付可以重复零次或多次
注意“a*”是可以匹配空串的
题解:
其余题解有DP 和 C++库中自带的正则库 不做多余解释
注意从后往前 “.*.*”或“a*a*”可以当作一个情况处理即可
别把条件落下
#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>#include<stack>#include<math.h>#define ll long longusing namespace std;int main(){ int t; char str1[3000],str2[3000]; scanf("%d",&t); while(t--){ scanf("%s %s",str1+1,str2+1); int len1 = strlen(str1+1),len2 = strlen(str2+1); for(int i = 3;i < len2;i++){ if(str2[i] == '*' && str2[i-2] == '*' && str2[i-1] == str2[i-3]){ for(int j = i-1;j < len2;j++) str2[j] = str2[j+2]; len2 -=2; } } str1[0] = '@',str2[0] = '@';// printf("%s %s\n",str1,str2); int ans = 0; while(len1 >= 0 && len2 >= 0){ if(!len1 && !len2){ ans = 1; break; } if(str1[len1] == str2[len2]){ len1--,len2--; continue; } if(str2[len2] == '.'){ len1--,len2--; continue; } if(str2[len2] == '*'){ if(str2[len2-1] != str1[len1] && str2[len2-1] != '.'){ len2 -= 2; continue; } if(str2[len2-1] == '.'){ int tmp = len1; while(str1[len1] == str1[tmp]) len1--; len2 -=2; continue; } if(str2[len2-1] == str1[len1]){ int tmp = len1; while(str1[len1] == str1[tmp]) len1--; len2 -= 2; continue; } } if(str2[len2] != str1[len1]){ if((str1[len1 + 1] == str2[len2]) && str2[len2 + 2] == '*'){ int tmp = 0; while(str1[len1 + 1 + tmp] == str2[len2]){ tmp++,len2--; } continue; } break; } } if(ans) puts("yes"); else puts("no"); } return 0;}
阅读全文
0 0
- hdu 6170 Two strings
- HDU 6170:Two strings
- HDU 6170 Two strings
- hdu 6170 Two strings
- HDU-6170 Two strings
- hdu 6170 Two strings
- HDU 6170 Two strings
- hdu-6170 Two strings
- hdu 6170 Two strings dp
- hdu 6170 Two strings(DP)
- HDU 6170(Two strings-DP)
- hdu 6170 Two strings(dp)
- hdu 6170 Two strings dp模拟
- Hdu 6170 Two strings【思维+Dp】
- HDU 6170 Two strings (dp)
- HDU 6170 Two strings (二维DP)
- hdu 6170 Two strings(线性dp)
- HDU 6170 Two strings(dp)
- iOS ATS测试跳过无效证书
- jedis总结
- maven生成可以直接运行的jar(包括依赖和mainclass)
- 静态注册 ACTION_SCREEN_ON & ACTION_SCREEN_OFF 收不到
- springmvc参数绑定
- HDU 6170 Two strings
- 一些关于工程的构想
- xgboost 实战以及源代码分析
- 海量数据处理-BloomFilter
- 欺小怕大吗?——CSDN的水印!
- leetcode[Sum of Square Numbers]
- 如何利用wordpress搭建自己的第一个博客
- java DecimalFormat常用的方法
- LeetCode 121. Best Time to Buy and Sell Stock--股票买入后再卖出,求最大收益,最多交易一次