Central Europe Regional Contest 2012 Problem c: Chemist’s vows
生活随笔
收集整理的這篇文章主要介紹了
Central Europe Regional Contest 2012 Problem c: Chemist’s vows
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
字符串處理的題目;
學習了一下string類的一些用法;
這個代碼花的時間很長,其實可以更加優化;
代碼:
1 #include<iostream> 2 #include<string> 3 using namespace std; 4 string dict[114]= {"he","h","li","be","b","c","n","o","f","ne" 5 ,"na","mg","al","si","p","s","cl","ar","k","ca" 6 ,"sc","ti","v","cr","mn","fe","co","ni","cu","zn" 7 ,"ga","ge","as","se","br","kr","rb","sr","y","zr" 8 ,"nb","mo","tc","ru","rh","pd","ag","cd","in","sn" 9 ,"sb","te","i","xe","cs","ba","hf","ta","w","re" 10 ,"os","ir","pt","au","hg","tl","pb","bi","po","at" 11 ,"rn","fr","ra","rf","db","sg","bh","hs","mt","ds" 12 ,"rg","cn","fl","lv","la","ce","pr","nd","pm","sm" 13 ,"eu","gd","tb","dy","ho","er","tm","yb","lu","ac" 14 ,"th","pa","u","np","pu","am","cm","bk","cf","es" 15 ,"fm","md","no","lr" 16 }; 17 18 bool go(string &s,int k) 19 { 20 if(k==s.length()) 21 return true; 22 for(int i=0; i<114; i++) 23 if(s.substr(k,dict[i].length())==dict[i] && go(s,k+dict[i].length())) 24 return true; 25 return false; 26 } 27 28 int main() 29 { 30 int tt; 31 cin>>tt; 32 string s; 33 while(tt--) 34 { 35 cin>>s; 36 cout<<(go(s,0)?"YES":"NO")<<endl; 37 } 38 return 0; 39 } View Code?
轉載于:https://www.cnblogs.com/yours1103/p/3350517.html
總結
以上是生活随笔為你收集整理的Central Europe Regional Contest 2012 Problem c: Chemist’s vows的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: struts2工作原理
- 下一篇: VS2003转VS2010 fatal