输入通配符表达式
一组字符串
输出:
返回匹配的结果,正确输出true,错误输出false
#include<iostream>
#include<string>
using namespace std;
bool fan(string a, string b)
{
int i;
for (i = 0; i < b.size(); i++)
{
if (a[i] == b[i])
{
continue;
}
else
{
if (a[i] == '?')
{
continue;
}
else if (a[i] == '*')
{
if (a[i + 1] == b[i + 1])
{
continue;
}
if (a[i + 1] == '?')
{
continue;
}
if ((b[i + 1] >= '0' && b[i + 1] <= '9') || (b[i + 1] >= 'A'&&b[i + 1] <= 'z'))
{
a.insert(i + 1, 1, '*');
}
}
else
{
return false;
}
}
}
if (i == a.size())
{
return true;
}
else
{
return false;
}
}
int main()
{
bool k;
string a, b;
while (cin >> a >> b)
{
k = fan(a, b);
if (k == 0)
{
cout << "false" << endl;
}
else
{
cout << "true" << endl;
}
}
}