Codeforces Round #189 (Div. 2) A. Magic Numbers【正难则反/给出一个数字串判断是否只由1,14和144组成】
2 seconds
256 megabytes
standard input
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.
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Print "YES" if n is a magic number or print "NO" if it's not.
114114
YES
1111
YES
441231
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;
}
Codeforces Round #189 (Div. 2) A. Magic Numbers【正难则反/给出一个数字串判断是否只由1,14和144组成】的更多相关文章
- Codeforces Round #189 (Div. 2) A. Magic Numbers
#include <iostream> #include <vector> #include <algorithm> #include <string> ...
- 构造 Codeforces Round #107 (Div. 2) B. Phone Numbers
题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> ...
- Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算
D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...
- Codeforces Round #189 (Div. 1 + Div. 2)
A. Magic Numbers 不能出现连续的3个4,以及1.4以外的数字. B. Ping-Pong (Easy Version) 暴力. C. Malek Dance Club 考虑\(x\)二 ...
- Codeforces Round #673 (Div. 2) C. k-Amazing Numbers(思维)
题目链接:https://codeforces.com/contest/1417/problem/C 题意 给出一个大小为 $n$ 的数组 $a$,计算当 $k$ 从 $1$ 到 $n$ 取值时在所有 ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 水题
A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 模拟
A. Magic Spheres Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. ...
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
随机推荐
- Aspose破解版本dll
下面是Aspose破解版本dll,并不是最新版本,有需要的可以下载使用: 下载Aspose各种破解版dll
- elasticsearch 中文API 基于查询的删除(九)
基于查询的删除API 基于查询的删除API允许开发者基于查询删除一个或者多个索引.一个或者多个类型.下面是一个例子. import static org.elasticsearch.index.que ...
- 订单风险系统BI
最近被公司叫去协助传统做维表查询服务,项目已经做完.和前端联调过程发现oracle对查询 sql和产品设计还是挺重要的.不能全部堆给代码去做,如何方便代码,代码优化到最高性能才是首要解决的事,前端才能 ...
- 查看MySql版本号命令
转自:https://blog.csdn.net/qq_38486203/article/details/80324014 这里介绍四中不同的方法,它们分别运行在不同的环境中,最后对每种方法的优劣以 ...
- NoSQL与关系数据库的比较
- Umount- Linux必学的60个命令
1.作用 umount命令的作用是卸载一个文件系统,它的使用权限是超级用户或/etc/fstab中允许的使用者. 2.格式 unmount -a [-fFnrsvw] [-t vfstype] [-n ...
- linux支持大容量硬盘
1.fdisk使用msdos格式分区,最大支持2T硬盘,要使用大于2T硬盘需使用parted命令使用GPT格式分区. 2.除修改分区格式外,linux内核需添加GPT分区格式支持,修改如下: CONF ...
- 验证sll证书与密钥
$crtParse = openssl_x509_parse($ssl_content); //$ssl_content 证书内容 .crt文件内容 if (!$crtParse) { return ...
- 【NOIP2018模拟11.01】树
题目 描述 题目大意 维护一个序列,支持三种操作: 1.修改一段区间,将这段区间内的所有数都andandand一个数. 2.询问区间和. 3.询问区间两两相加的平方和. N≤10000N\leq 10 ...
- JavaScript RegExp 对象的三种方法
JavaScript RegExp 对象有 3 个方法:test().exec() 和 compile().(1) test() 方法用来检测一个字符串是否匹配某个正则表达式,如果匹配成功,返回 tr ...