-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmallest Substring
More file actions
75 lines (66 loc) · 1.03 KB
/
Smallest Substring
File metadata and controls
75 lines (66 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<stdio.h>
#include <stdlib.h>
int c[52]={0},len1=0;
int substring(char b[1001],int m)
{
int i,count[52]={0},d,len=0;
for(i=0;i<m;i++)
{
if(b[i]>=97 && b[i]<=122)
d=97;
else
d=39;
if(count[b[i]-d]==0)
{
count[b[i]-d]++;
len++;
}
if(len==len1)
{
return m;
}
}
return 9999;
}
int main()
{
int i,j,k,min=9999,temp,d;
char a[1001];
scanf("%s",a);
int len=strlen(a);
for(i=0;a[i];i++)
{
if(a[i]>=97 && a[i]<=122)
d=97;
else
d=39;
if(c[a[i]-d]==0)
{
c[a[i]-d]++;
len1++;
}
}
for(i=0;i<len;i++)
{
for(j=i;j<len;j++)
{
int m=0;
char b[1001]={'\0'};
for(k=i;k<=j;k++)
{
b[m]=a[k];
m++;
}
if(m>=len1)
{
temp=substring(b,m);
if(temp<min)
{
min=temp;
//printf("min=%d",min);
}
}
}
}
printf("%d",min);
}