Codeforces Magic Numbers
/*
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.
*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
const int mod = 1000007;
const int high = 100;
int main()
{
fast;
string s;
int len , i , one , four;
while(cin >> s)
{
len = s.length();
one = four = 0;
if(s[0] != '1')
{
outn("NO");
continue;
}
bool magic=false , other=false;
for(i=0; i<len; i++)
{
four = 0;
one = 0;
if(s[i] == '1')
{
int j = i+1;
one++;
while(j < len)
{
if(s[j] == '4') four++;
else if(s[j] == '1') one++;
else
{
other = true;
break;
}
j++;
}
//cout << one << "; ";
if(four>=1 and four <= 2) magic = true;
if(one == len) magic = true;
if(other) magic = false;
}
// else if(s[i] == '4')
// {
// if(s[i-1] == '1' or s[i-2] == '1') magic = true;
// }
}
if(magic) outn("YES");
else outn("NO");
}
return 0;
}
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.
*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
const int mod = 1000007;
const int high = 100;
int main()
{
fast;
string s;
int len , i , one , four;
while(cin >> s)
{
len = s.length();
one = four = 0;
if(s[0] != '1')
{
outn("NO");
continue;
}
bool magic=false , other=false;
for(i=0; i<len; i++)
{
four = 0;
one = 0;
if(s[i] == '1')
{
int j = i+1;
one++;
while(j < len)
{
if(s[j] == '4') four++;
else if(s[j] == '1') one++;
else
{
other = true;
break;
}
j++;
}
//cout << one << "; ";
if(four>=1 and four <= 2) magic = true;
if(one == len) magic = true;
if(other) magic = false;
}
// else if(s[i] == '4')
// {
// if(s[i-1] == '1' or s[i-2] == '1') magic = true;
// }
}
if(magic) outn("YES");
else outn("NO");
}
return 0;
}
Comments
Post a Comment