# Cf 189 div2 A-Magic Numbers

Source: Internet
Author: User
A. Magic Numberstime limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

A magic number is a number formed by concatenation of number1, 14 and 144.
We can use each of these numbers any number of times. Therefore 14144,141 414 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 integerN, (1 limit ≤ limitNLimit ≤ limit 109 ).
This number doesn' t contain leading zeros.

Output

Print "YES" ifNIs a magic number or print "NO"
If it's not.

Sample test (s) input
`114114`
Output
`YES`
Input
`1111`
Output
`YES`
Input
`441231`
Output
`NO`

`Question. The following code is used:`
`#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#define inf 1000000000using namespace std;int main(){    //freopen("input.txt","r",stdin);    //freopen("output.txt","w",stdout);    char s[100];    cin>>s;    int i,j;    int l=strlen(s);    for(i=0;i<l;i++){         if(s[i]!='1'&&s[i]!='4')            break;    }    if(i<l||s[0]!='1'){         cout<<"NO"<<endl;         return 0;    }    for(i=0;i<l;i++){         if(s[i]!='1') continue;         for(j=i+1;j<l;j++){             if(s[j]=='1') break;         }          if(j-i>3){             cout<<"NO"<<endl;             return 0;          }    }    cout<<"YES"<<endl;    return 0;}`
Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.