forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchemistsvows.cpp
78 lines (66 loc) · 1.69 KB
/
chemistsvows.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <bits/stdc++.h>
using namespace std;
vector<string> table = {
"H","He",
"Li","Be","B","C","N","O","F","Ne",
"Na","Mg","Al","Si","P","S","Cl","Ar",
"K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr",
"Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te","I","Xe",
"Cs","Ba","Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn",
"Fr","Ra","Rf","Db","Sg","Bh","Hs","Mt","Ds","Rg","Cn","Fl","Lv",
"La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu",
"Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm","Md","No","Lr"
};
void solve() {
string s;
cin >> s;
s = '*' + s;
vector<bool> works(s.size(),false);
works[0] = true;
for(int i = 1; i <= s.size(); i++) {
for(auto j : table) {
if(j.size() > i) continue;
int ptr1 = i;
int ptr2 = j.size()-1;
bool good = true;
while(ptr2 >= 0) {
if(j[ptr2] != s[ptr1]) {
good = false;
}
ptr1--;
ptr2--;
}
if(good && works[i-j.size()]) {
works[i] = true;
}
}
}
/*
for(auto i : s) {
cout << i << " ";
}
cout << endl;
for(auto i : works) {
cout << i << " ";
}
cout << endl;
*/
if(works[s.size()-1]) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
int main() {
for(auto& i : table) {
for(auto& j : i) {
j = tolower(j);
}
}
int cases;
cin >> cases;
while(cases--) {
solve();
}
}