320A Magic Numbers

  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. string s;
  5. cin>>s;
  6. int ln=s.length();
  7. bool f=0;
  8. for(int i=0;i<ln;i++){
  9. if(s[i]=='4' and s[i+1]=='4' and s[i+2]=='4')
  10. { f=1;
  11. }
  12. else if(s[i]!='1' and s[i]!='4')
  13. { f=1;
  14. }
  15. else if(s[0]=='4' )
  16. { f=1;
  17. }
  18. }
  19. if(f==1) cout<<"NO"<<endl;
  20. else cout<<"YES";
  21.  
  22.  
  23. }

Comments

Popular posts from this blog

Codeforce Problem 1703A. YES or YES?

Aptitude test assistant programmer 2018

1041A. Heist solution