A. Magic Numbers

   日期:2020-11-12     浏览:151    评论:0    
核心提示:A. Magic Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Th

A. Magic Numbers
time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.

You’re given a number. Determine if it is a magic number or not.

Input

The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn’t contain leading zeros.

Output
Print “YES” if n is a magic number or print “NO” if it’s not.

Examples

input
114114

output
YES

input
1111

output
YES

input
441231

output
NO

My Answer Code:


#include<bits/stdc++.h>
using namespace std;
int main()
{ 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    { 
        if((s[i]!='1'&&s[i]!='4')||s[0]!='1'){ cout<<"NO"<<'\n';return 0;}
    }
    for(int i=0;i+2<s.length();i++)
    { 
        if(s[i]=='4'&&s[i+1]=='4'&&s[i+2]=='4'){ cout<<"NO"<<'\n';return 0;}
    }
    cout<<"YES"<<'\n';
    return 0;
}
 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服