Codeforces Round #436 B. Polycarp and Letters

题意:给你一串长度为n的字符,由大小写字母组成,求连续的小写子串中不同字母个数的最大值。

Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0

思路:水题,瞎搞搞就OK。

代码:
#include<iostream>
#include<string.h>
#include<cmath>
using namespace std;

char s[250];
int vis[30];

int main(){
    int l,sum=0,k=0;
    cin>>l>>s;
    if(l==1){
        if(s[0]>='a'&&s[0]<='z')cout<<1<<endl;
        else cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<l;i++){
        if(s[i]>='A'&&s[i]<='Z'){
            memset(vis,0,sizeof(vis));
            k=0;
        }
        else {
            if(vis[s[i]-'a']==0){
                vis[s[i]-'a']=1;
                k++;
                sum=max(sum,k);
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/ljy08163268/p/7634643.html