链接: http://codeforces.com/problemset/problem/864/B
题目截图如下:
代码放在下面:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int count_nums_not_0(int a[]){ //返回非0的数值有几个,即多少个字母
int count = 0;
for(int i = 1;i <= 26 ;i++){
if(a[i]){
count++;
}
}
return count;
}
int main(){
int n,nums[30],record_index[205];
char str[205];
while(scanf("%d",&n) != EOF && n){
int maxx = 0;
getchar();
gets(str);
memset(record_index,0,sizeof(record_index));
int k = 1;record_index[0] = 0;
for(int i = 0;i < n;i++){
if(str[i] >= 'A' && str[i] <= 'Z'){ //记录大写字母的下标,下标为0对应着str[0]的下标
record_index[k++] = i;
}
} //k is the number of the upperStr
record_index[k] = n; // str[n],nums[]数组一共有 k+2个数值
for(int i = 0;i < (k-1+2);i++){ //i遍历到 nums[]的倒数第二个就好了
memset(nums,0,sizeof(nums));
for(int j = record_index[i];j < record_index[i+1];j++){
//printf("uppe str(a,b) is %c\n",str[j]); //对的
nums[(str[j] - 'a' + 1)] += 1; //核心代码,对小写区间进行处理,用nums[]数组记录26个字母有多少个
}
maxx = max(maxx,count_nums_not_0(nums)); //maxx is the ans.
}
printf("%d\n",maxx);
}
}
没有了,谢谢,2019.3.21 大一下学期