A string S is passed as the input. Two words W1 and W2 which are present in the string S are also passed as the input. The program must find the minimum distance D between W1 and W2 in S (in forward or reverse order) and print D as the output.

[ad_1]

A string S is passed as the input. Two words W1 and W2 which are present in the string S are also passed as the input. The program must find the minimum distance D between W1 and W2 in S (in forward or reverse order) and print D as the output.
/*
 * Question :
 *
 *
 *	Minimum Distance between words[AMAZON]
 *	Posted on June 12, 2018
 *
 *	A string S is passed as the input.Two words w1 and w2 which are present in the string S are also passed as the input.
 *	The program  must find the minimum distance d between W1 and W2 in S (in forward or reverse order)and print D as the output.
 *
 *	Example 1:
 *
 *		Input:
 *			The brown quick frog quick the
 *			the
 *			quick
 *		Output:
 *			1
 *	Explanation:
 *		quick and the are adjacent as the last two words.Hence distance between them is 1.
 *
 *
 *	Example 2:
 *
 *		Input:
 *			the quick the brown quick brown the frog
 *			quick
 *			frog
 *		Output:
 *			3
 *
 */

//  Program:

#include 
#include 

int main()
{
	char sentence[50][50],w1[20],w2[20];
	int i=0,l=0,m=0,min=100,index1[50],index2[50];

	while(scanf(
		i++;								// you have to use,  ctrl+z to end the input reading

	strcpy(w1,sentence[i-2]);
	strcpy(w2,sentence[i-1]);
	i=i-2;

	for(int j=0;j

[ad_2]

Please follow and like us:
Content Protection by DMCA.com