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 keyboard? answer me <br>​
Grace [21]

Answer:

something you put your fingers on

Explanation:

3 0
3 years ago
Read 2 more answers
What is the definition of digital literacy?
babunello [35]
Digital literacy is part of media literacy,Both include the idea of info literacy,Which is the ability to effectively find, Identify, Evaluate,And use info., Digital literacy especially applies to media from the internet, Smartphone,Video games,And other things us teens use now & days....Hope that helps (Also next time up your points if you want more Answers) (:
4 0
3 years ago
Read 2 more answers
What services are used to help speed the development and deployment of internal custom applications?
PtichkaEL [24]

A, Protocol

because An application service provider (ASP) is a business providing computer-based services to customers over a network; such as access to a particular software application (such as customer relationship management) using a standard protocol (such as HTTP).

7 0
3 years ago
Read 2 more answers
Cheri needs to write a small program that interacts with the user. What step will allow her to do this?
Alinara [238K]

Answer:

Including a input statement

Explanation:

You need a input statement in order for it to work, here´s an example;

script.parent.click <u>then</u>

you need the ¨.mouse¨ after parent or it wouldnt work.

8 0
3 years ago
Read 2 more answers
Will give brainlyist
In-s [12.5K]

i think its the first sentence: Mobile devices have become the main source of communication for many people around the world

if im wrong im dum ;-;

6 0
3 years ago
Read 2 more answers
Other questions:
  • When pasting an object which has been copied from a different slide, where on the slide does the object paste, assuming nothing
    15·1 answer
  • Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
    14·1 answer
  • Format Painter cannot be used to copy only character attributes. True or False
    12·1 answer
  • Which item refers to an illusion of figures and shapes in motion, which we commonly see in movies and video games?
    9·1 answer
  • Your computer has gradually slowed down. What's the most likely reason?
    8·1 answer
  • Fill in the blank
    11·1 answer
  • Edhesive coding practice 3.4​
    12·1 answer
  • Multiple Choice
    9·1 answer
  • A customer has a computer for a home business, but wants to have another computer as a web server. What would be the best soluti
    11·2 answers
  • Users at UC need to be able to quickly create a Resource record from the Project record's Chatter feed How should the App Builde
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!