字符串处理的题目;
学习了一下string类的一些用法;
这个代码花的时间很长,其实可以更加优化;
代码:
#include<iostream>
#include<string>
using namespace std;
string dict[]= {"he","h","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"
}; bool go(string &s,int k)
{
if(k==s.length())
return true;
for(int i=; i<; i++)
if(s.substr(k,dict[i].length())==dict[i] && go(s,k+dict[i].length()))
return true;
return false;
} int main()
{
int tt;
cin>>tt;
string s;
while(tt--)
{
cin>>s;
cout<<(go(s,)?"YES":"NO")<<endl;
}
return ;
}