交错01串
来源:互联网 发布:马云开创淘宝 编辑:程序博客网 时间:2024/05/21 10:32
牛客网链接
如果一个01串任意两个相邻位置的字符都是不一样的,我们就叫这个01串为交错01串。例如: “1”,”10101”,”0101010”都是交错01串。
小易现在有一个01串s,小易想找出一个最长的连续子串,并且这个子串是一个交错01串。小易需要你帮帮忙求出最长的这样的子串的长度是多少。
- 这个没有啥的,就是根据输入,遍历,查找最长的交错串就好,比较容易,也没啥坑。
#include<iostream>#include<string>using namespace std;int main(){ string s; cin>>s; int num = s.size(); int max = 1 , total = 1; for(int i = 1;i < num ; i++){ if((s[i]-'0')^(s[i-1]-'0')){ total++; }else{ max = total>max ? total : max; total = 1; } } max = total>max ? total : max; cout<<max; return 0;}
阅读全文
1 0
- 交错01串
- 交错01串
- 交错01串
- [编程题] 交错01串
- 网易笔试:交错01串
- [编程题] 交错01串
- [编程题] 交错01串
- 网易2018校招内推笔试-交错01串
- 交错01串-网易2018校招内推
- 十、网易2017<交错01串>
- 网易编程题 交错01串
- 2018网易秋招内推笔试题——交错01串
- 网易2017内推 [编程题] 交错01串@Java
- 2018年网易校招内推编程题之交错01串
- 2018网易内推笔试-交错01串(python)
- 网易2018校招内推编程题集合:交错01串 [python]
- 2018校招网易笔试——最长01交错子串
- 网易2018内推笔试题解析(交错01串)
- Why is QsslSocket working with Qt 5.3 but not Qt 5.7 on Debian Stretch?
- 算法效能分析
- Hexo深度使用
- Error Curves
- Mapper配置之ResultMap详解
- 交错01串
- Excel 中多行时快速生成自增长序号
- Unity6--缩放、旋转、欧拉角
- Java基础——Servlet(四)
- 终端命令积累
- webservice
- AVD中应用程序的卸载
- spring bean的生命周期
- java的RandomAccessFile的使用详解