-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1984B.cpp
More file actions
58 lines (48 loc) · 1.25 KB
/
Copy path1984B.cpp
File metadata and controls
58 lines (48 loc) · 1.25 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define umap unordered_map
#define f(i, x, n) for(ll i = x; i < n; i++)
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main() {
optimize();
ll t;
cin >> t;
while (t--) {
ull x;
cin >> x;
vector<int> num;
while (x > 0) {
num.pb(x%10);
x /= 10;
}
reverse(num.begin(), num.end());
if (num[0] != 1) {
cout << "NO" << endl;
} else if (num[num.size()-1] < 0 || num[num.size()-1] > 8) {
cout << "NO" << endl;
} else {
bool ok = true;
num[0] = -1;
num[num.size()-1] = -1;
for (ll i = 0; i < num.size()-1; i++) {
if(num[i] == -1) {
continue;
} else {
if (num[i] < 1 || num[i] > 9) {
ok = false;
break;
}
}
}
if (ok) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
}