当前位置:
首页 >
Codeforces 864 B Polycarp and Letters 暴力
发布时间:2023/12/31
48
豆豆
生活随笔
收集整理的这篇文章主要介绍了
Codeforces 864 B Polycarp and Letters 暴力
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
题目链接: http://codeforces.com/problemset/problem/864/B
题目描述: 看看连续子串都是小写字母的字母种类最多是多少
解题思路: 暴力, 枚举起点和终点, 然后判断是不是都是小写字母, 如果是的话那就判断字母的种类是多少, 取一个最大值就好了
代码:
#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; } View Code思考: 没啥可说的, 就是题目的意思挺烦人的, 解释的很繁琐, 我读题花了好长的时间
转载于:https://www.cnblogs.com/FriskyPuppy/p/7599218.html
总结
以上是生活随笔为你收集整理的Codeforces 864 B Polycarp and Letters 暴力的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 方舟烹饪锅怎么用 方舟生存进化
- 下一篇: kafka0.8消费者实例