搜索
您的当前位置:首页正文

【思维题】Magic Numbers

来源:星星旅游

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

题意:
本题英文简单易懂,不写题意了

思路:
典型的有思路(或者说做过类似的)可以一分钟搞定,没思路的钻牛角尖半小时写了一大堆都不一定会对。

代码如下:

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n)
	{
		if(n%10!=1&&n%100!=14&&n%1000!=144)
		{
			cout<<"NO"<<endl;
			break;
		}
		n/=10;
	}
	if(!n) cout<<"YES"<<endl;
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Top