A. Magic Numbers
time 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 numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but1444, 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
【代码】:
#include <bits/stdc++.h>
using namespace std;
string a;
int i,k;
bool f=true;
int main() {
cin >> a;
for (i=0;i<a.length();i++)
{
if(a[0]!='1') f=0; //首位非1开头 错
if(a[i]!='1'&&a[i]!='4') f=0;//有非1,4的字符出现 错 if(a[i]=='1') //开头为1 计数器k清零
k=0;
else if(a[i]=='4') //出现4个数超过2 错
{
k++;
if(k>2) f=0;
}
}
if (f) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}

  

最新文章

  1. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(13)-系统日志和异常的处理③
  2. 【转】Apache 配置虚拟主机三种方式
  3. play(1) 第一个简单的应用
  4. codeforces 675C C. Money Transfers(贪心)
  5. jquery直接获取html页面元素
  6. ASP.NET JSON的序列化和反序列化 之 Newtonsoft.Json
  7. ubuntu/linux mint 创建proc文件的三种方法(四)
  8. 面试之路(28)-反转链表(reverse ListNode)
  9. p9半幺群
  10. 058、flannel概述(2019-03-27 周三)
  11. Linux使用ntpdate和ntpd进行时间同步
  12. 20165205 2017-2018-2 《Java程序设计》实验四 Android程序设计
  13. [转]8款实用的jQuery/CSS3最新插件应用
  14. How to disable a plugin when Jenkins is down?
  15. 【BZOJ】1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心)
  16. SQL UNION操作符使用
  17. java 第七章 面向对象高级特性
  18. 《Java编程思想》阅读笔记二
  19. C++11并发编程:async,future,packaged_task,promise
  20. [转]LVS+Keepalived负载均衡配置

热门文章

  1. springMVC和springBoot区别
  2. CODE[VS]4633:Mz树链剖分练习
  3. css3的3D变形
  4. python验证码识别PIL+pytesseract
  5. 洛谷 P1155 双栈排序
  6. DSMM之数据处理安全
  7. Spring MVC(二)--Spring MVC登陆实例
  8. WhaleCTF之web-Find me
  9. KMP模板题 Number Sequence HDU1711
  10. Ubuntu 链接ln的使用:创建和删除符号链接