hihocoder #1061 : Beautiful String
2016-07-15 11:29
302 查看
#include<fstream> #include<iostream> #include<string> #include<math.h> using namespace std; #define FOR(i,b,e) for(int i=(b);i<=(e);i++) #define FORE(i,b,e) for(int i=(b);i>=(e);i--) #define maxnum 503 int step,last,pres; int main() { #ifdef DEBUG_ ifstream fin("G:/1.txt"); #define cin fin #endif int M,N; string str; cin>>N; FOR(i,1,N){ cin>>M; cin>>str; if(M<3){ cout<<"NO"<<endl; continue; } step=0;last=0;pres=0; char a=0; int flag=0; FOR(i,0,M-1){ if(a+1==str[i]){ step=(step==2?2:step+1); last=pres; pres=1; a=str[i]; if(step==2&&last==1){ flag=1; break; } }else if(a==str[i]){ pres++; if(step==1){ if(pres>last) step=0; }else if(step==2){ if(pres==last){ flag=1; break; } } }else{ step=0; last=0; pres=1; a=str[i]; } } if(flag) cout<<"YES"<<endl; else cout<<"NO"<<endl; } cout<<endl; return 0; }
相关文章推荐
- 如何写一篇好的技术博客
- redis配置文件
- 微信公众号开发教程[011]-自定义菜单以及个性化菜单
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- iOS开发:UITableview的多选功能实现
- 归并排序
- 设计模式之单例模式
- Java文件操作大全(4)
- [转]ListView学习笔记(一)——缓存机制
- 测试GeoGebra博客
- RequireJS基础(三)
- Ajax+Struts2实现验证码验证功能实例代码
- opencv 拉伸、扭曲、旋转图像-仿射变换 opencv1 / opencv2 / python cv2(代码)
- Linux Bash shell (for循环)
- [置顶] SSH日期录入,日期精确不能精准到时分秒处理
- iOS 广告轮播图
- date 显示日期与时间
- 防御Linux下DDOS攻击
- 浅谈数论(四)扩展欧几里得算法与乘法逆元
- SDWebImage 的使用