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]
2 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]2 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
Why must programs written in a high-level language be translated into machine language?
eimsori [14]
The only thing that a computer actually understands is machine language. English-like constructs are gibberish to a computer, so they need to be translated by a compiler to machine language to run natively.
4 0
2 years ago
How many units are considered a full time student at a community college in California?
Crazy boy [7]

Answer:

12

Explanation:

According to Saddleback college located in California;

12 units are considered full-time student status.

You may take as little as 0.5 units or as many as 19.0 units during a single semester. To take more than 19 units you are required to obtain special permission from the Counseling Department.

7 0
2 years ago
Which term is used to describe a software application that is secretly placed on a user system to gather information and relay i
BARSIC [14]

Answer: Spyware?

Explanation:

6 0
3 years ago
What happens if a sequence is out of order?
andre [41]

Answer:

If you are trying to put the events in order and they are out of order you will probaly get the question wrong so make sure the events are in order.

Explanation:

6 0
2 years ago
Read 2 more answers
Se tiene un pilar de hormigón de 30 cm de lado y 5 m de altura. Presenta una densidad de 2400 kg/m3 y una resistencia a la compr
kakasveta [241]

Answer:

El pilar no podrá soportar una masa de 10 toneladas

Explanation:

La dimensión del pilar de hormigón se da de la siguiente manera;

La longitud del lado, s = 30 cm = 0,3 m

La altura del pilar, h = 5 m

La densidad del pilar, ρ = 2,400 kg / m³

La resistencia a la compresión del pilar, σ = 500 kg / m²

El área de la sección transversal del pilar, A = s² = 0.3 m × 0.3 m = 0.09 m²

La masa del pilar, m = ρ × A × h = 2,400 × 0.09 × 5 = 1,080

La masa del pilar, m = 1.080 kg

Tenemos;

\sigma = \dfrac{F}{A}

Dónde;

F = La carga aplicada

A = El área de la sección transversal

∴ F = A × σ

F = 0,09 m² × 500 kg / m² = 45 kg

Por tanto, la carga que el pilar puede soportar sin compresión = 45 kg <10 toneladas = 9.071,847 kg

El pilar no podrá soportar una masa de 10 toneladas.

6 0
2 years ago
Other questions:
  • Which environment variable affects the number of past commands used in the current shell session?
    14·1 answer
  • How do I mirror cast my smart lg tv?​
    11·1 answer
  • Write a function in Java that implements the following logic: Given a string and an int n, return a string made of n repetitions
    15·1 answer
  • True or false.local and cloud backup differs in where the backup is saved
    15·2 answers
  • What number system do people in America use?
    10·2 answers
  • Find different between manocots and dicots clarify with example​
    14·1 answer
  • I dunno what to write my memo thing about ⁻³⁻
    10·2 answers
  • In the second example with modulus math, why can't Eve find the solution?
    10·1 answer
  • (e) The vending machine stores the quantity of items available in a database table called ITEMS
    6·1 answer
  • Refer to the exhibit. Host B on subnet Teachers transmits a packet to host D on subnet Students. Which Layer 2 and Layer 3 addre
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!