UVALive 6257 Chemist's vows


  1 #include<iostream>  
  2 #include<string.h>  
  3 #include<stdio.h>  
  4 #include<ctype.h>  
  5 #include<algorithm>  
  6 #include<stack>  
  7 #include<queue>  
  8 #include<set>  
  9 #include<math.h>  
 10 #include<vector>  
 11 #include<map>  
 12 #include<deque>  
 13 #include<list>  
 14 using namespace std;
 15 char a[1000000];
 16 char e[1000000];
 17 int main()
 18 {
 19     int n,len;
 20     cin>>n;
 21     while(n--)
 22     {
 23         cin>>a;
 24         len=strlen(a);
 25         memset(e,0,sizeof(e));
 26         int b=0;
 27         for(int i=0;i<len;i++)
 28         {
 29             if(i==0)
 30             {
 31             if(
 32             a[i]=='h'||
 33             a[i]=='b'||
 34             a[i]=='c'||
 35             a[i]=='n'||
 36             a[i]=='o'||
 37             a[i]=='f'||
 38             a[i]=='v'||
 39             a[i]=='y'||
 40             a[i]=='i'||
 41             a[i]=='w'||
 42             a[i]=='u'||
 43             a[i]=='k'||
 44             a[i]=='p'||
 45             a[i]=='s'
 46             )
 47             {
 48             b=b+1;
 49             e[0]=1;
 50             }
 51             else
 52             e[0]=0;
 53             }
 54             if(i!=0&&e[i-1]==0)
 55             {
 56                 if(
 57                 (a[i-1]=='h'&&a[i]=='e')||
 58                 (a[i-1]=='l'&&a[i]=='i')||
 59                 (a[i-1]=='b'&&a[i]=='e')||
 60                 (a[i-1]=='n'&&a[i]=='e')||
 61                 (a[i-1]=='n'&&a[i]=='a')||
 62                 (a[i-1]=='m'&&a[i]=='g')||
 63                 (a[i-1]=='a'&&a[i]=='l')||
 64                 (a[i-1]=='s'&&a[i]=='i')||
 65                 (a[i-1]=='c'&&a[i]=='l')||
 66                 (a[i-1]=='a'&&a[i]=='r')||
 67                 (a[i-1]=='c'&&a[i]=='a')||
 68                 (a[i-1]=='s'&&a[i]=='c')||
 69                 (a[i-1]=='t'&&a[i]=='i')||
 70                 (a[i-1]=='c'&&a[i]=='r')||
 71                 (a[i-1]=='m'&&a[i]=='n')||
 72                 (a[i-1]=='f'&&a[i]=='e')||
 73                 (a[i-1]=='c'&&a[i]=='o')||
 74                 (a[i-1]=='n'&&a[i]=='i')||
 75                 (a[i-1]=='c'&&a[i]=='u')||
 76                 (a[i-1]=='z'&&a[i]=='n')||
 77                 (a[i-1]=='g'&&a[i]=='a')||
 78                 (a[i-1]=='g'&&a[i]=='e')||
 79                 (a[i-1]=='a'&&a[i]=='s')||
 80                 (a[i-1]=='s'&&a[i]=='e')||
 81                 (a[i-1]=='b'&&a[i]=='r')||
 82                 (a[i-1]=='k'&&a[i]=='r')||
 83                 (a[i-1]=='r'&&a[i]=='b')||
 84                 (a[i-1]=='s'&&a[i]=='r')||
 85                     //"he","h","li","be","b","c","n","o","f","ne"
 86 //,"na","mg","al","si","p","s","cl","ar","k","ca"
 87 //,"sc","ti","v","cr","mn","fe","co","ni","cu","zn"
 88 //,"ga","ge","as","se","br","kr","rb","sr",
 89                 (a[i-1]=='z'&&a[i]=='r')||
 90                 (a[i-1]=='n'&&a[i]=='b')||
 91                 (a[i-1]=='m'&&a[i]=='o')||
 92                 (a[i-1]=='t'&&a[i]=='c')||
 93                 (a[i-1]=='r'&&a[i]=='u')||
 94                 (a[i-1]=='r'&&a[i]=='h')||
 95                 (a[i-1]=='p'&&a[i]=='d')||
 96                 (a[i-1]=='a'&&a[i]=='g')||
 97                 (a[i-1]=='c'&&a[i]=='d')||
 98                 (a[i-1]=='i'&&a[i]=='n')||
 99                 (a[i-1]=='s'&&a[i]=='n')||
100                 (a[i-1]=='s'&&a[i]=='b')||
101                 (a[i-1]=='t'&&a[i]=='e')||
102                 (a[i-1]=='x'&&a[i]=='e')||
103                 (a[i-1]=='c'&&a[i]=='s')||
104                 (a[i-1]=='b'&&a[i]=='a')||
105                 (a[i-1]=='h'&&a[i]=='f')||
106                 (a[i-1]=='t'&&a[i]=='a')||
107                 (a[i-1]=='r'&&a[i]=='e')||
108                 (a[i-1]=='o'&&a[i]=='s')||
109                 (a[i-1]=='i'&&a[i]=='r')||
110                 (a[i-1]=='p'&&a[i]=='t')||
111                 (a[i-1]=='a'&&a[i]=='u')||
112                 (a[i-1]=='h'&&a[i]=='g')||
113                 (a[i-1]=='t'&&a[i]=='l')||
114                 (a[i-1]=='p'&&a[i]=='b')||
115                 (a[i-1]=='b'&&a[i]=='i')||
116                     //"he","h","li","be","b","c","n","o","f","ne"
117 //,"na","mg","al","si","p","s","cl","ar","k","ca"
118 //,"sc","ti","v","cr","mn","fe","co","ni","cu","zn"
119 //,"ga","ge","as","se","br","kr","rb","sr","y","zr"
120 //,"nb","mo","tc","ru","rh","pd","ag","cd","in","sn"
121 //,"sb","te","i","xe","cs","ba","hf","ta","w","re"
122 //,"os","ir","pt","au","hg","tl","pb","bi"
123                 (a[i-1]=='p'&&a[i]=='o')||
124                 (a[i-1]=='a'&&a[i]=='t')||
125                 (a[i-1]=='r'&&a[i]=='n')||
126                 (a[i-1]=='f'&&a[i]=='r')||
127                 (a[i-1]=='r'&&a[i]=='a')||
128                 (a[i-1]=='r'&&a[i]=='f')||
129                 (a[i-1]=='d'&&a[i]=='b')||
130                 (a[i-1]=='s'&&a[i]=='g')||
131                 (a[i-1]=='b'&&a[i]=='h')||
132                 (a[i-1]=='h'&&a[i]=='s')||
133                 (a[i-1]=='m'&&a[i]=='t')||
134                 (a[i-1]=='d'&&a[i]=='s')||
135                 (a[i-1]=='r'&&a[i]=='g')||
136                 (a[i-1]=='c'&&a[i]=='n')||
137                 (a[i-1]=='f'&&a[i]=='l')||
138                 (a[i-1]=='l'&&a[i]=='v')||
139                 (a[i-1]=='l'&&a[i]=='a')||
140                 (a[i-1]=='c'&&a[i]=='e')||
141                 (a[i-1]=='p'&&a[i]=='r')||
142                 (a[i-1]=='n'&&a[i]=='d')||
143                 (a[i-1]=='p'&&a[i]=='m')||
144                 (a[i-1]=='s'&&a[i]=='m')||
145                 (a[i-1]=='e'&&a[i]=='u')||
146                 //"he","h","li","be","b","c","n","o","f","ne"
147 //,"na","mg","al","si","p","s","cl","ar","k","ca"
148 //,"sc","ti","v","cr","mn","fe","co","ni","cu","zn"
149 //,"ga","ge","as","se","br","kr","rb","sr","y","zr"
150 //,"nb","mo","tc","ru","rh","pd","ag","cd","in","sn"
151 //,"sb","te","i","xe","cs","ba","hf","ta","w","re"
152 //,"os","ir","pt","au","hg","tl","pb","bi","po","at"
153 //,"rn","fr","ra","rf","db","sg","bh","hs","mt","ds"
154 //,"rg","cn","fl","lv","la","ce","pr","nd","pm","sm"
155                 (a[i-1]=='g'&&a[i]=='d')||
156                 (a[i-1]=='t'&&a[i]=='b')||
157                 (a[i-1]=='d'&&a[i]=='y')||
158                 (a[i-1]=='h'&&a[i]=='o')||
159                 (a[i-1]=='e'&&a[i]=='r')||
160                 (a[i-1]=='t'&&a[i]=='m')||
161                 (a[i-1]=='y'&&a[i]=='b')||
162                 (a[i-1]=='l'&&a[i]=='u')||
163                 (a[i-1]=='a'&&a[i]=='c')||
164                 (a[i-1]=='t'&&a[i]=='h')||
165                 (a[i-1]=='p'&&a[i]=='a')||
166                 (a[i-1]=='n'&&a[i]=='p')||
167                 (a[i-1]=='p'&&a[i]=='u')||
168                 (a[i-1]=='a'&&a[i]=='m')||
169                 (a[i-1]=='c'&&a[i]=='m')||
170                 (a[i-1]=='b'&&a[i]=='k')||
171                 (a[i-1]=='c'&&a[i]=='f')||
172                 (a[i-1]=='e'&&a[i]=='s')||
173                 (a[i-1]=='f'&&a[i]=='m')||
174                 (a[i-1]=='m'&&a[i]=='d')||
175                 (a[i-1]=='n'&&a[i]=='o')||
176                 (a[i-1]=='l'&&a[i]=='r')
177                 )
178                 {
179                     b=b+2;
180                     e[i]=2;
181                 }
182             }
183             if(i!=0&&e[i-1]==2)
184             {
185                 if(a[i]=='h'||
186             a[i]=='b'||
187             a[i]=='c'||
188             a[i]=='n'||
189             a[i]=='o'||
190             a[i]=='f'||
191             a[i]=='v'||
192             a[i]=='y'||
193             a[i]=='i'||
194             a[i]=='w'||
195             a[i]=='u'||
196             a[i]=='k'||
197             a[i]=='p'||
198             a[i]=='s')
199             { b=b+1;
200             e[i]=1;}
201             else 
202             e[i]=0;
203             }
204             if(e[i-1]==1&&i!=0)
205             {
206                 if(
207                     a[i]=='h'||
208             a[i]=='b'||
209             a[i]=='c'||
210             a[i]=='n'||
211             a[i]=='o'||
212             a[i]=='f'||
213             a[i]=='v'||
214             a[i]=='y'||
215             a[i]=='i'||
216             a[i]=='w'||
217             a[i]=='u'||
218             a[i]=='k'||
219             a[i]=='p'||
220             a[i]=='s'||
221                 (a[i-1]=='h'&&a[i]=='e')||
222                 (a[i-1]=='l'&&a[i]=='i')||
223                 (a[i-1]=='b'&&a[i]=='e')||
224                 (a[i-1]=='n'&&a[i]=='e')||
225                 (a[i-1]=='n'&&a[i]=='a')||
226                 (a[i-1]=='m'&&a[i]=='g')||
227                 (a[i-1]=='a'&&a[i]=='l')||
228                 (a[i-1]=='s'&&a[i]=='i')||
229                 (a[i-1]=='c'&&a[i]=='l')||
230                 (a[i-1]=='a'&&a[i]=='r')||
231                 (a[i-1]=='c'&&a[i]=='a')||
232                 (a[i-1]=='s'&&a[i]=='c')||
233                 (a[i-1]=='t'&&a[i]=='i')||
234                 (a[i-1]=='c'&&a[i]=='r')||
235                 (a[i-1]=='m'&&a[i]=='n')||
236                 (a[i-1]=='f'&&a[i]=='e')||
237                 (a[i-1]=='c'&&a[i]=='o')||
238                 (a[i-1]=='n'&&a[i]=='i')||
239                 (a[i-1]=='c'&&a[i]=='u')||
240                 (a[i-1]=='z'&&a[i]=='n')||
241                 (a[i-1]=='g'&&a[i]=='a')||
242                 (a[i-1]=='g'&&a[i]=='e')||
243                 (a[i-1]=='a'&&a[i]=='s')||
244                 (a[i-1]=='s'&&a[i]=='e')||
245                 (a[i-1]=='b'&&a[i]=='r')||
246                 (a[i-1]=='k'&&a[i]=='r')||
247                 (a[i-1]=='r'&&a[i]=='b')||
248                 (a[i-1]=='s'&&a[i]=='r')||
249                     //"he","h","li","be","b","c","n","o","f","ne"
250 //,"na","mg","al","si","p","s","cl","ar","k","ca"
251 //,"sc","ti","v","cr","mn","fe","co","ni","cu","zn"
252 //,"ga","ge","as","se","br","kr","rb","sr",
253                 (a[i-1]=='z'&&a[i]=='r')||
254                 (a[i-1]=='n'&&a[i]=='b')||
255                 (a[i-1]=='m'&&a[i]=='o')||
256                 (a[i-1]=='t'&&a[i]=='c')||
257                 (a[i-1]=='r'&&a[i]=='u')||
258                 (a[i-1]=='r'&&a[i]=='h')||
259                 (a[i-1]=='p'&&a[i]=='d')||
260                 (a[i-1]=='a'&&a[i]=='g')||
261                 (a[i-1]=='c'&&a[i]=='d')||
262                 (a[i-1]=='i'&&a[i]=='n')||
263                 (a[i-1]=='s'&&a[i]=='n')||
264                 (a[i-1]=='s'&&a[i]=='b')||
265                 (a[i-1]=='t'&&a[i]=='e')||
266                 (a[i-1]=='x'&&a[i]=='e')||
267                 (a[i-1]=='c'&&a[i]=='s')||
268                 (a[i-1]=='b'&&a[i]=='a')||
269                 (a[i-1]=='h'&&a[i]=='f')||
270                 (a[i-1]=='t'&&a[i]=='a')||
271                 (a[i-1]=='r'&&a[i]=='e')||
272                 (a[i-1]=='o'&&a[i]=='s')||
273                 (a[i-1]=='i'&&a[i]=='r')||
274                 (a[i-1]=='p'&&a[i]=='t')||
275                 (a[i-1]=='a'&&a[i]=='u')||
276                 (a[i-1]=='h'&&a[i]=='g')||
277                 (a[i-1]=='t'&&a[i]=='l')||
278                 (a[i-1]=='p'&&a[i]=='b')||
279                 (a[i-1]=='b'&&a[i]=='i')||
280                     //"he","h","li","be","b","c","n","o","f","ne"
281 //,"na","mg","al","si","p","s","cl","ar","k","ca"
282 //,"sc","ti","v","cr","mn","fe","co","ni","cu","zn"
283 //,"ga","ge","as","se","br","kr","rb","sr","y","zr"
284 //,"nb","mo","tc","ru","rh","pd","ag","cd","in","sn"
285 //,"sb","te","i","xe","cs","ba","hf","ta","w","re"
286 //,"os","ir","pt","au","hg","tl","pb","bi"
287                 (a[i-1]=='p'&&a[i]=='o')||
288                 (a[i-1]=='a'&&a[i]=='t')||
289                 (a[i-1]=='r'&&a[i]=='n')||
290                 (a[i-1]=='f'&&a[i]=='r')||
291                 (a[i-1]=='r'&&a[i]=='a')||
292                 (a[i-1]=='r'&&a[i]=='f')||
293                 (a[i-1]=='d'&&a[i]=='b')||
294                 (a[i-1]=='s'&&a[i]=='g')||
295                 (a[i-1]=='b'&&a[i]=='h')||
296                 (a[i-1]=='h'&&a[i]=='s')||
297                 (a[i-1]=='m'&&a[i]=='t')||
298                 (a[i-1]=='d'&&a[i]=='s')||
299                 (a[i-1]=='r'&&a[i]=='g')||
300                 (a[i-1]=='c'&&a[i]=='n')||
301                 (a[i-1]=='f'&&a[i]=='l')||
302                 (a[i-1]=='l'&&a[i]=='v')||
303                 (a[i-1]=='l'&&a[i]=='a')||
304                 (a[i-1]=='c'&&a[i]=='e')||
305                 (a[i-1]=='p'&&a[i]=='r')||
306                 (a[i-1]=='n'&&a[i]=='d')||
307                 (a[i-1]=='p'&&a[i]=='m')||
308                 (a[i-1]=='s'&&a[i]=='m')||
309                 (a[i-1]=='e'&&a[i]=='u')||
310                 //"he","h","li","be","b","c","n","o","f","ne"
311 //,"na","mg","al","si","p","s","cl","ar","k","ca"
312 //,"sc","ti","v","cr","mn","fe","co","ni","cu","zn"
313 //,"ga","ge","as","se","br","kr","rb","sr","y","zr"
314 //,"nb","mo","tc","ru","rh","pd","ag","cd","in","sn"
315 //,"sb","te","i","xe","cs","ba","hf","ta","w","re"
316 //,"os","ir","pt","au","hg","tl","pb","bi","po","at"
317 //,"rn","fr","ra","rf","db","sg","bh","hs","mt","ds"
318 //,"rg","cn","fl","lv","la","ce","pr","nd","pm","sm"
319                 (a[i-1]=='g'&&a[i]=='d')||
320                 (a[i-1]=='t'&&a[i]=='b')||
321                 (a[i-1]=='d'&&a[i]=='y')||
322                 (a[i-1]=='h'&&a[i]=='o')||
323                 (a[i-1]=='e'&&a[i]=='r')||
324                 (a[i-1]=='t'&&a[i]=='m')||
325                 (a[i-1]=='y'&&a[i]=='b')||
326                 (a[i-1]=='l'&&a[i]=='u')||
327                 (a[i-1]=='a'&&a[i]=='c')||
328                 (a[i-1]=='t'&&a[i]=='h')||
329                 (a[i-1]=='p'&&a[i]=='a')||
330                 (a[i-1]=='n'&&a[i]=='p')||
331                 (a[i-1]=='p'&&a[i]=='u')||
332                 (a[i-1]=='a'&&a[i]=='m')||
333                 (a[i-1]=='c'&&a[i]=='m')||
334                 (a[i-1]=='b'&&a[i]=='k')||
335                 (a[i-1]=='c'&&a[i]=='f')||
336                 (a[i-1]=='e'&&a[i]=='s')||
337                 (a[i-1]=='f'&&a[i]=='m')||
338                 (a[i-1]=='m'&&a[i]=='d')||
339                 (a[i-1]=='n'&&a[i]=='o')||
340                 (a[i-1]=='l'&&a[i]=='r')
341                 )
342                 {b=b+1;
343                 e[i]=1;}
344 //"he","h","li","be","b","c","n","o","f","ne"
345 //,"na","mg","al","si","p","s","cl","ar","k","ca"
346 //,"sc","ti","v","cr","mn","fe","co","ni","cu","zn"
347 //,"ga","ge","as","se","br","kr","rb","sr","y","zr"
348 //,"nb","mo","tc","ru","rh","pd","ag","cd","in","sn"
349 //,"sb","te","i","xe","cs","ba","hf","ta","w","re"
350 //,"os","ir","pt","au","hg","tl","pb","bi","po","at"
351 //,"rn","fr","ra","rf","db","sg","bh","hs","mt","ds"
352 //,"rg","cn","fl","lv","la","ce","pr","nd","pm","sm"
353 //,"eu","gd","tb","dy","ho","er","tm","yb","lu","ac"
354 //,"th","pa","u","np","pu","am","cm","bk","cf","es"
355 //,"fm","md","no","lr"
356             }
357         }
358         if(b==len)
359         printf("YES\n");
360         else
361         printf("NO\n");
362     }
363     return 0;
364 }
View Code

 

posted @ 2014-07-30 09:38  qscqesze  阅读(339)  评论(0编辑  收藏  举报