Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- main()
- {
- int count1 = 0, count2 = 0, i, j, flag,flag1,count3 = 0;
- char str[] = {'h','i','m','a','l','a','y','a','s',' ','i','s',' ','o','n','e',' ','t','h','e',' ','b','e','s','t',' ','m','o','u','n','t','a','i','n','s'};
- char search[] = {'o','n','e',' ','o','f',' ','t','h','e',' ','b','e','s','t'};
- char str1[] = {'m','e','l','o','d','y',' ','i','s',' ','o','n','e',' ','o','f',' ','t','h','e',' ','b','e','s','t',' ','c','h','o','c','o','l','a','t','e'};
- while (str[count1] != '\0')
- count1++;
- while (search[count2] != '\0')
- count2++;
- while(str1[count3] != '\0')
- count3++;
- for (i = 0; i <= count1 - count2; i++)
- {
- for (j = i; j < i + count2; j++)
- {
- flag = 1;
- if (str[j] != search[j - i])
- {
- flag = 0;
- break;
- }
- }
- if (flag == 1)
- break;
- }
- for (i = 0; i <= count3 - count2; i++)
- {
- for (j = i; j < i + count2; j++)
- {
- flag1 = 1;
- if (str[j] != search[j - i])
- {
- flag1 = 0;
- break;
- }
- }
- if (flag1 == 1)
- break;
- }
- if (flag == flag1)
- printf("Both inputs have same common substring");
- else
- printf("Inputs dont have same common substring");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement