Codeforces 864 B Polycarp and Letters 暴力
题目链接: http://codeforces.com/problemset/problem/864/B
题目描述: 看看连续子串都是小写字母的字母种类最多是多少
解题思路: 暴力, 枚举起点和终点, 然后判断是不是都是小写字母, 如果是的话那就判断字母的种类是多少, 取一个最大值就好了
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <cstdio> #include <map> #include <iterator> #include <string> using namespace std; map<char, int > m; int n; int ok(string & str, int s, int e) { for( int i = s; i <= e; i++ ) { if( (int)str[i]>=65 && (int)str[i]<= 90 ) { return 0; } } return 1; } int main() { cin >> n; string str; cin >> str; int res = 0; for( int i = 0; i < n; i++ ) { for( int j = i; j < n; j++ ) { if( !ok(str, i, j) ) { continue; } m.clear(); int cnt = 0; for( int k = i; k <= j; k++ ) { if( m[str[k]] == 0 ) { m[str[k]] = 1; cnt ++; } } if( res < cnt ) res = cnt; } } cout << res << endl; return 0; }
思考: 没啥可说的, 就是题目的意思挺烦人的, 解释的很繁琐, 我读题花了好长的时间
posted on 2017-09-26 22:01 FriskyPuppy 阅读(184) 评论(0) 编辑 收藏 举报