zoukankan      html  css  js  c++  java
  • 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

      思考: 没啥可说的, 就是题目的意思挺烦人的, 解释的很繁琐, 我读题花了好长的时间

  • 相关阅读:
    multer实现图片上传
    multer使用
    前端常用网址收集
    MySQL连表查询
    express相关操作
    小程序多列选择器的使用
    给小程序picker添加年月日时分秒
    DB中的null在js中的显示结果
    IDEA快捷键
    springboot导jar包并部署运行
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7599218.html
Copyright © 2011-2022 走看看