Codeforces 864 B Polycarp and Letters 暴力
生活随笔
收集整理的這篇文章主要介紹了
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 暴力的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 方舟烹饪锅怎么用 方舟生存进化
- 下一篇: 车损险要不要买 车损险能够买吗