cf Magic Numbers

http://codeforces.com/contest/320/problem/A

 1 #include <cstdio>

 2 #include <cstring>

 3 using namespace std;

 4 

 5 char str[100];

 6 

 7 int main()

 8 {

 9     scanf("%s",str);

10     int k=strlen(str);

11     for(int i=0; i<k; i++)

12     {

13         if(str[i]!='1'&&str[i]!='4')

14         {

15             printf("NO\n");

16             return 0;

17         }

18         if(str[i]=='4')

19         {

20             if(i==0)

21             {

22                 printf("NO\n");

23                 return 0;

24             }

25             else if(str[i-1]=='4'&&str[i-2]!='1')

26             {

27                 printf("NO\n");

28                 return 0;

29             }

30         }

31     }

32     printf("YES\n");

33     return 0;

34 }
View Code

 

你可能感兴趣的:(number)