博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Central Europe Regional Contest 2012 Problem c: Chemist’s vows
阅读量:5066 次
发布时间:2019-06-12

本文共 1441 字,大约阅读时间需要 4 分钟。

字符串处理的题目;

学习了一下string类的一些用法;

这个代码花的时间很长,其实可以更加优化;

代码:

1 #include
2 #include
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")<
View Code

 

转载于:https://www.cnblogs.com/yours1103/p/3350517.html

你可能感兴趣的文章
7NiuYun云存储UploadPicture
查看>>
Window 的引导过程
查看>>
python与 Ajax跨域请求
查看>>
App右上角数字
查看>>
从.NET中委托写法的演变谈开去(上):委托与匿名方法
查看>>
小算法
查看>>
201521123024 《java程序设计》 第12周学习总结
查看>>
贪吃蛇游戏改进
查看>>
新作《ASP.NET MVC 5框架揭秘》正式出版
查看>>
在WPF中使用Caliburn.Micro搭建MEF插件化开发框架
查看>>
IdentityServer4-用EF配置Client(一)
查看>>
asp.net core系列 35 EF保存数据(2) -- EF系列结束
查看>>
WPF程序加入3D模型
查看>>
WPF中实现多选ComboBox控件
查看>>
读构建之法第四章第十七章有感
查看>>
android访问链接时候报java.net.MalformedURLException: Protocol not found
查看>>
dwz ie10一直提示数据加载中
查看>>
Windows Phone开发(4):框架和页 转:http://blog.csdn.net/tcjiaan/article/details/7263146
查看>>
Windows Phone Marketplace 发布软件全攻略
查看>>
Unity3D研究院之打开Activity与调用JAVA代码传递参数(十八)【转】
查看>>