forked from Saad2714/Cpp-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.c
More file actions
50 lines (43 loc) · 907 Bytes
/
2.c
File metadata and controls
50 lines (43 loc) · 907 Bytes
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
/*INPUT=string str containing lower-case english alphabets and integer l
OUTPUT=find the number of distinct substrings of length l of the given string str */
#include<stdio.h>
#include<string.h>
int main()
{
char str[20000],ch1[20000],ch2[20000];//array declarations
int i,j,k,l,n,check=0,count=0;//variable declarations
scanf("%s %d",str,&n);//inputs of string and length of substring we want
l=strlen(str);//length of the string we input
if(n>l)
{
printf("0");
}
else
{
for(i=0;i<(l-n+1);i++)
{
for(j=0;j<n;j++)
{
ch1[j]=str[i+j];//inserting the substrings of the length which we want
}
for(j=0;j<(l-n-i);j++)
{
for(k=0;k<n;k++)
{
ch2[k]=str[i+j+k+1];
}
if(strncmp(ch1,ch2,n)==0)//comparing strings ch1 and ch2
{
check++;
}
}
if(check==0)
{
count++;
}
check=0;
}
printf("%d",count);// count is our answer
}
return 0;
}