给出一个字符串,求该字符串的一个子串s,s包含A-Z中的全部字母,并且s是所有符合条件的子串中最短的,输出s的长度。如果给出的字符串中并不包括A-Z中的全部字母,则输出No Solution。
Input
第1行,1个字符串。字符串的长度 <= 100000。
Output
输出包含A-Z的最短子串s的长度。如果没有符合条件的子串,则输出No Solution。
Sample Input
BVCABCDEFFGHIJKLMMNOPQRSTUVWXZYZZ
Sample Output
28
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int b,c[27];
char a[100010];
int l(int *a)
{
int i,ge=0;;
for(i=0; i<=25; i++)
if(a[i]>=1)
ge++;
if(ge<26)
return 1;
else
return 0;
}
int t(int n)
{
int i,ge=0;
for(i=0; i<=n; i++)
{
if(c[a[i]-'A']>=2)
ge++;
}
if(ge==n+1)
return 1;
return 0;
}
int main()
{
int i,ans,e,s;
ans=100000;
scanf("%s",a);
b=strlen(a);
e=0;
s=0;
for(;;)
{
while(e<b&&l(c))
{
c[a[e]-'A']++;
e++;
}
if(l(c))
break;
ans=min(ans,e-s);
c[a[s]-'A']--;
s++;
}
if(ans<26||ans==100000)
printf("No Solution\n");
else
printf("%d\n",ans);
}