# Educational Codeforces Round 32 Problem 888C - K-Dominant Character

1) Link to the problem: http://codeforces.com/contest/888/problem/C

2) Description:

You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant if each substring of s with length at least contains this character c.

You have to find minimum k such that there exists at least one k-dominant character.

Input

The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).

Output

Print one number — the minimum value of k such that there exists at least one k-dominant character.

3) 思路：

4) Code：

#include <iostream>
#include <cstring>
using namespace std;
int main(){
string s;
cin>>s;
int n = s.size();
int min = INT_MAX;

for(int i = 0; i < 52; i++)
{
char c;
if(i<26)
c = (char)('a' + i);
else
c = (char)('A' + i - 26);

int count = 0;
int maxgap = 0;
for(int j = 0; j < n; j++){
if(s[j] == c)
{
if(maxgap < count)
maxgap = count;
count = 0;
}
else {
count ++;
}
}
if(maxgap < count)
maxgap = count;
if(maxgap < min)
min = maxgap;
if(min==0)
break;
}
cout << min + 1;
return 0;
}

posted @ 2017-11-13 13:18 rgvb178 阅读(...) 评论(...) 编辑 收藏