题解 | #字符串通配符#
字符串通配符
https://www.nowcoder.com/practice/43072d50a6eb44d2a6c816a283b02036
#include <cctype> #include <iostream> #include <regex> using namespace std; int main() { string wildcard; string totest; string reg; getline(cin,wildcard); getline(cin,totest); int flag = 0; for(auto x:wildcard){ if(x=='?'){ reg+="[0-9a-zA-Z.]"; flag = 0; continue; }if(x=='*'){ if(flag == 1){ continue; }else{ reg+="[0-9a-zA-Z.]*"; flag = 1; continue; } }else{ flag = 0; x = tolower(x); reg.push_back(x); } } regex r(reg); if(regex_match(totest, r)){ cout<<"true"; }else{ cout<<"false"; } } // 64 位输出请用 printf("%lld")
正则表达式很慢