Two strings
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 680 Accepted Submission(s): 269
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
3 aa a* abb a.* abb aab
Sample Output
yes yes no
题意
字符串模式匹配,'.'匹配任何一个字符,'*'表示它的前一个字符可以任意出现(0次或多次),给出字符串和模式串,询问是否匹配
分析
和标准正则表达式不同的是".*"模式串在题意下不能匹配"abcde"这样的字符串
按题意".*"的意思是相同字符的0个或多个重复串
那么我们把模式串中的".*"替换成"(.)\1*"即可
不会的东西好多,多校没见过的解法也好多#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <list>
#include <bitset>
#include <stack>
#include <stdlib.h>
#include <regex>
#define lowbit(x) (x&-x)
#define e exp(1.0)
#define eps 1e-8
//ios::sync_with_stdio(false);
// auto start = clock();
// cout << (clock() - start) / (double)CLOCKS_PER_SEC;
typedef long long ll;
typedef long long LL;
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
string a,b;
cin>>a>>b;
b=regex_replace(b,regex("\\.\\*"),"(.)\\1*");
regex_match(a,regex(b))?cout<<"yes"<<endl:cout<<"no"<<endl;
}
return 0;
}