fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. bool isMatch(string s, string p) {
  9. if(p[0] == '.' && p[1] == '*')
  10. return true;
  11. bool ok = true;
  12. int pozs = 0;
  13. int pozp = 0;
  14. p+=' ';
  15. s+=' ';
  16. while(pozp < p.size()-1)
  17. if(((p[pozp]>='a'&&p[pozp]<='z')||p[pozp] == '.')&&p[pozp+1] == '*'){
  18. while(s[pozs] == p[pozp] || p[pozp] == '.' && pozs<s.size()-1 && s[pozs] != p[pozp+2]){pozs++;}
  19. pozp += 2;
  20. }
  21. else if(p[pozp+1]!='*' && p[pozp] >='a' && p[pozp] <= 'z'){
  22. if(p[pozp] == s[pozs] || p[pozp] == '.')
  23. pozs++,pozp++;
  24. else
  25. return false;
  26. }
  27. else if(pozp < p.size() - 1 && pozs == s.size() -1)
  28. return false;
  29.  
  30. if(pozs == s.size() -1 &&p.size() - pozp == 1)
  31. return true;
  32. return false;
  33. }/******************************************************************************
  34.  
  35. Welcome to GDB Online.
  36. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  37. C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  38. Code, Compile, Run and Debug online from anywhere in world.
  39.  
  40. *******************************************************************************/
  41.  
  42.  
  43. int main()
  44. {
  45.  
  46. cout<< isMatch("abd",".*c");
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5312KB
stdin
45
stdout
1