Code-:Submission #125905287 - Codeforces
Question-:Problem - A - Codeforces
Someone…
Your solution isn’t even passing the samples
2 Likes
Yeah I know that.Can you tell me the error in my code?
Good to see, Your approach is quite close but need some modifications, Try to find ‘144’ first then ‘14’ then after ‘1’, this way You’ll find AC.
Look at following code(with some modifications),
void solve()
{
std::string s;
std::cin >> s;
int key = 1;
while (s.size() >= 0 || key == 1)
{
int i = 0;
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4')
{
s.erase(i, 3);
}
else if (s[i] == '1' && s[i + 1] == '4')
{
s.erase(i, 2);
}
else if (s[i] == '1')
{
s.erase(i, 1);
}
else if (s.size() == 0)
{
break;
}
else
{
key = 0;
break;
}
}
if (key)
{
std::cout << "YES\n";
}
else
std::cout << "NO\n";
}