fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int check = 0;
  5. void find_magic (string s)
  6. {
  7. int len = s.length();
  8. string S1="", S2="", S3="";
  9. if (len >= 1) S1 = S1 + s[0];
  10. if (len >= 2) S2 = S2 + s[0] + s[1];
  11. if (len >= 3) S3 = S3 + s[0] + s[1] + s[2];
  12. if (S1 == "1" && s.length()>=1)
  13. {
  14. if (len == 1)
  15. {
  16. check = 1;
  17. return;
  18. }
  19. else find_magic (s.substr(1, s.length()-1));
  20. }
  21. if (S2 == "14" && len>=2)
  22. {
  23. if (len == 2)
  24. {
  25. check = 1;
  26. return;
  27. }
  28. else find_magic (s.substr(2, s.length()-2));
  29. }
  30. if (S3 == "144" && len>=3)
  31. {
  32. if (len == 3)
  33. {
  34. check = 1;
  35. return;
  36. }
  37. else find_magic (s.substr(3, s.length()-3));
  38. }
  39. return;
  40. }
  41.  
  42. int main ()
  43. {
  44. string s;
  45. cin>>s;
  46. find_magic (s);
  47. if (check == 1) cout<<"YES";
  48. else cout<<"NO";
  49. return 0;
  50. }
Success #stdin #stdout 0s 4360KB
stdin
114144
stdout
YES