fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. string a; cin >> a;
  6. a = '0'+a+'0';
  7. for(int i=1;i<a.size()-1;++i){
  8. if(a[1] == '4' || (a[i] != '1' && a[i] != '4')){
  9. cout << "NO";
  10. return 0;
  11. }else if(a[i] == '1') continue;
  12. else{
  13. if(a[i-1] == '1' || a[i+1] == '1') continue;
  14. else if(a[i-1] == '4' && a[i+1] != '4') continue;
  15. else if(a[i-1] != '4' && a[i+1] == '4') continue;
  16. else{
  17. cout << "NO";
  18. return 0;
  19. }
  20. }
  21. }
  22. cout << "YES";
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5272KB
stdin
1114141441
stdout
YES