1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include<iostream> #include<string.h> using namespace std; bool isMatching(char *str, char *reg, int n, int m, int i, int j) { if(i==n&&j==m) return true; if(i>=n||j>=m) return false; if(reg[j]<'a'||reg[j]>'z') return false; if(j+1>=m&®[j]==str[i]) return true; if(j+1>=m) return false; if(reg[j+1]=='?') { //0 case if(isMatching(str, reg, n, m, i, j+2)) return true; //1 case if(reg[j]==str[i]) return isMatching(str, reg, n, m, i+1, j+2); return false; } if(reg[j+1]=='*') { //0 case if(isMatching(str, reg, n, m, i, j+2)) return true; while(i<n&&str[i]==reg[j]) { if(isMatching(str, reg, n, m, i++, j+2)) return true; } return false; } if(reg[j]==str[i]) return isMatching(str, reg, n, m, i+1, j+1); return false; } int main() { char reg[10], str[256]; scanf("%s%s",str, reg); cout<<isMatching(str, reg, strlen(str), strlen(reg), 0, 0)<<endl; return 0; } |
-
upload with new input
-
result: Success time: 0.02s memory: 2728 kB returned value: 0
kaaapil ka*pil
0
-
result: Success time: 0.01s memory: 2728 kB returned value: 0
kaaaapil kaaa?pil
0
-
result: Success time: 0.01s memory: 2728 kB returned value: 0
kaaapil kaaa?pil
1
-
result: Success time: 0.02s memory: 2728 kB returned value: 0
kaapil kaaa?pil
1
-
result: Success time: 0.02s memory: 2728 kB returned value: 0
kapil kapil
1



