-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode320A.cpp
More file actions
42 lines (31 loc) · 745 Bytes
/
Copy pathcode320A.cpp
File metadata and controls
42 lines (31 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Contest : Codeforces
* Problem : 320A - Magic Numbers
* Link : https://codeforces.com/contest/320/problem/A
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
bool solve(string str) {
string aux = "";
for (int i = 0; i < str.size(); i++) {
if (str[i] != '1' && str[i] != '4') return false;
aux += str[i];
cerr << aux << endl;
if (str[i] == '1') aux = "1";
else if (aux == "4") return false;
else if (aux == "14") continue;
else if (aux == "144") aux.clear();
else
return false;
}
return true;
}
int main() {
fastio
string str;
cin >> str;
printf("%s\n", solve(str) ? "YES" : "NO");
return 0;
}