Skip to content

Commit 3ac3ee0

Browse files
committed
I am submitting my problem, please merge it after reviewing
1 parent c540474 commit 3ac3ee0

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

ToyObsession/problem.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
We are to input a string of characters(say, s1= XxxyXxxXXxY) and a character(say, X) that belongs to that string
2+
( The string represents the collection of toys and the character represents the most beautiful toy)
3+
we are to input a number that denotes the no. of beautiful toys needed ( smaller than equal to the maximum beautiful toys, say 2 )
4+
now we are to print the smallet length (as in no. of characters) of the substring
5+
eg here 2 X containing substrigs are... XxxyX XxxX XX
6+
5 4 2
7+
max min therefor 2 printed. \(>o<)/

ToyObsession/solution.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
int main()
4+
{
5+
long long int T,m;
6+
scanf("%lld",&T);
7+
for(m=0;m<T;m++)
8+
9+
{ char s1[100001],s2[100001],a;
10+
long long int i=1,k,b,j=0,c,l,u,N,z=999999,arr[100001],brr[100001];
11+
scanf("%s%s%lld",s1,s2,&N);
12+
k = strlen(s1);
13+
a = s2[0];
14+
for(i=0;i<k;i++)
15+
{if(s1[i]==a)
16+
{
17+
arr[j]=i;
18+
j++;
19+
}
20+
}
21+
i=0;
22+
j--;
23+
while(j-(N-1)>=0)
24+
{
25+
brr[i] = arr[j]-arr[j-(N-1)]+1;
26+
i++;
27+
j--;
28+
}
29+
30+
for(l=0;l<i;l++)
31+
{
32+
if(brr[l]<z)
33+
z = brr[l];
34+
}
35+
printf("%lld\n",z);
36+
}
37+
return 0;
38+
}
39+
40+

0 commit comments

Comments
 (0)