1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sattari [20]
3 years ago
15

Find the Nearest Repeated Entries in an Array People do not like reading text in which a word is used multiple times in a short

paragraph. You are to write a program which helps identify such a problem. Write a program that takes as input an array and finds the distance between closest pairs of equal entries. For example if s = <"All, "work", "and", "no", "play", "makes", "for", "no", "work", "and", "no", "fun", "and", "no", "results">, then the second and third occurrences of "no" is the closest pair.
Computers and Technology
1 answer:
e-lub [12.9K]3 years ago
3 0

Answer:

The following program is written in C++ Programming Language.

#include <iostream>   //header file

#include<cstring>    //header file

using namespace std;   //using namespace

int main()    //main function

{

int num;

cout<<"Enter the no. of words: ";   //print message

cin>>num;    //get input from the user

char input[num][10];

int visited[num]={0};

for(int i=0;i<num;i++)

{

cin>>input[i];

}

for(int i=0;i<num;i++)

{

int distance=1000,left,right,prev,flag;

left=i;

prev=i;

if(visited[i]==0)

{

flag=0;

for(int j=i+1;j<num;j++)

{

if(strcmp(input[j],input[i])==0)

{

if(j-prev<distance)

{

left=prev;

right=j;

distance=j-prev;

}

prev=j;

visited[j]=1;

flag=1;

}

}

if(flag==1)

cout<<"The closest distance between the pair of "<<input[i]<<" is "<<distance<<" and pair is ("<<left<<" , "<<right<<")"<<endl;

}

}

return 0;

}

Explanation:

Here, we define two header file <iostream> and <cstring> and using namespace "std".

Then, we define the main() function.

Then, we declare an integer variable "num"  in which we get the input from the user.

Then, we initialized the two array variable first is character array "input" and integer array visited and after all, we follow the instructions.

You might be interested in
Pictures that you can click on to tell your computer what to do.
Tom [10]
What do you mean ? I’m confused..
6 0
3 years ago
Read 2 more answers
What is the best wi-fi name you have ever seen?
elena-s [515]

Answer:

bill wi the science fi

Explanation:

8 0
2 years ago
What does a wholesaler do?
Svetach [21]
Wholesalers acquire goods from manufacturers, farmers or miners, holds them then distributes them to retailers.
6 0
3 years ago
Is it possible for a PowerPoint user to add notes to slides and see the added comments
Arturiano [62]

Answer:

I am not for sure on this, but yes I think it is possible for the PowerPoint user to add notes to slides and see the added comments. If it isn't possible I know for a fact on Google slides it is possible.

:

hope this helps! :)

7 0
3 years ago
Please help with my Python code - Functions
ollegr [7]

Answer:

Explanation:

see attached for help

7 0
3 years ago
Other questions:
  • Two or more computers that transfer information between computers are called a
    7·1 answer
  • How does the team know what to work upon during the iteration
    6·1 answer
  • Need answers for 11&amp;12. Due today. Thanks.
    14·1 answer
  • Jeffrey works with a huge database of spreadsheet records each day. To organize and identify these spreadsheets, he wants to ass
    8·1 answer
  • Write a class called Counter that represents a simple tally counter, which might be used to count people as they enter a room. T
    9·1 answer
  • (Please answer! Correct answer gets brainliest!)
    5·2 answers
  • . What type of device is a computer? Where does it use?​
    14·1 answer
  • What is the result of the following code?<br><br> x=7//2+10%2**4<br><br> print(x)
    15·1 answer
  • YASHARI earns $27,000 per year, is single, and lives in Wyoming. She has $7000 in Direct Subsidized loans and another $19,000 in
    9·1 answer
  • What do you mean by computer ethics?​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!