http://acm.hdu.edu.cn/showproblem.php?pid=6170php
.
匹配任意字符,x*
匹配任意長度的 x
(x
爲任意字符,長度能夠爲 0 )c++
#include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <regex> #include <sys/types.h> const int MAX_N = 3e3 + 7; char s1[MAX_N], s2[MAX_N],sr[MAX_N * 1000]; inline bool solve() { gets(s1); gets(s2); std::regex rx("\\.\\*"); char fmt[] = "(.)\\1*"; *std::regex_replace(sr, s2, s2 + strlen(s2), rx, fmt) = '\0'; return regex_match(s1,std::regex(sr)); return false; } int main() { int T; scanf("%d", &T); getchar(); while(T--) puts(solve() ? "yes" : "no"); return 0; }
sys/types.h
, regex
regex_replace(s,first,last,rgx,tmt,flags)
目標地址,源首,源末,替換目標,替換內容,regex_match(s,rgx)
源,匹配內容