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
What is the difference between posting and transfer in ICT please I need the answer before TMR​
Radda [10]

Answer: b

Explanation: trust

7 0
2 years ago
3.6 lesson practice
Thepotemich [5.8K]

what...? how is this a question??

5 0
3 years ago
Which input and output pair is correct for a bicycle?
mrs_skeptik [129]

Answer:

I'm pretty sure its B.

Explanation:

Input: Force is applied to the pedals by the rider's feet then..

Process: the chain and gear system convert the energy to cause...

Output: the rear wheels to turn and make the bike go foward

6 0
3 years ago
Binary divide 1101011 by 111​
denis-greek [22]

is this computer subject

5 0
3 years ago
Read 2 more answers
Explain how communication is smooth and efficient working​
ohaa [14]

Answer:

To communicate effectively, you need to avoid distractions and stay focused. Inconsistent body language. Nonverbal communication should reinforce what is being said, not contradict it. If you say one thing, but your body language says something else, your listener will likely feel that you're being dishonest.

8 0
2 years ago
Read 2 more answers
Other questions:
  • You will write a program that reads a binary file that contains records of creatures. Each record can be stored in a Creature st
    10·1 answer
  • (I'LL GIVE BRAINLIST)
    10·2 answers
  • Will give brainliest!!!!!!!!!!!!
    6·2 answers
  • Interior gateway protocols are used by routers in order to share information within a single
    9·1 answer
  • Websites whose URL’s contain tildes (~) are usually published by the government. TRUE or FALSE.
    8·2 answers
  • Cisco has created a proprietary layer 2 protocol used to manage VLAN configuration between switches called:________a. VLAN Confi
    11·1 answer
  • What techniques overcome resistance and improve the credibility of a product? Check all that apply.
    8·1 answer
  • Identify the correct characteristics of Python tuples. Check all that apply.
    9·1 answer
  • A line graph is a great tool for showing changes over time. Why is a line graph better than other graphs at showing this type of
    6·1 answer
  • A diagram of a ten-node network that uses ten routers
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!