subject

5.29 LAB: Replacement words
Write a program that replaces words in a sentence. The input begins with an integer indicating the number of word replacement pairs (original and replacement) that follow. The next line of input begins with an integer indicating the number of words in the sentence that follows. Any word on the original list is replaced.

Ex: If the input is:

3 automobile car manufacturer maker children kids
15 The automobile manufacturer recommends car seats for children if the automobile doesn't already have one.
then the output is:

The car maker recommends car seats for kids if the car doesn't already have one.
You can assume the original words are unique. For coding simplicity, follow each output word by a space, even the last one.

Hint: For words to replace, use two vectors: One for the original words, and the other for the replacements.

Your program must define and call the following function that returns index of word's first occurrence in wordList. If not found, then the function returns -1.
int FindWordInWordList(vector wordList, string wordToFind).

This is what i have.
#include

#include

using namespace std;

int FindWordInWordList(vector wordList, string wordToFind);

int main()

{

int a, b, i ;

vector word, replace;

string str ;

cin >> a ;

for(i = 0; i < a; i++)

{

cin >> str;

word. push_back(str);

cin >> str ;

replace. push_back(str) ;

}

cin >> b;

for(i = 0; i < b; i++)

{

cin >> str ;

int pos = FindWordInWordList(word, str) ;

if(pos == -1)

cout << str ;

else

cout << replace[pos] ;

if(i != b-1)

cout << " " ;

}

cout << endl ;

return 0;

}

int FindWordInWordList(vector wordList, string wordToFind)

{

for(int i = 0; i < wordList. size(); i++)

{

if(wordList[i] == wordToFind)

return i;

}

return -1;

}

the only problem i am having is putting a space at the end of the sentence.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 19:10
What a backup plan that you have created in a event you encounter a situation
Answers: 2
question
Computers and Technology, 22.06.2019 21:30
Elements such as fonts colors visual structure graphics and the interface of a web page should complement each other to ensure blank
Answers: 3
question
Computers and Technology, 23.06.2019 15:30
Write a program in plp assembly that counts up by one starting from zero (or one) inside a loop and writes this value to the leds every time the value is increased. the memory address of the leds is 0xf0200000. the table below shows the meaning and an example usage of the instructions covered in the video, plp instructions for project 1. instruction example usage meaning load immediate li $t0, 8 register $t0 is set to the value, 8. store word sw $t2, 0($t1) the value in register $t1 is used as the memory address. the value in register $t2 is copied into this memory address. add addiu $t4, $t3, 29 register $t4 is assigned the sum of 29 and the value in register $t3. jump j your_label_name the program jumps to the line following the label, "your_label_name: ". label your label name: defines a label called "your_label_name: " that can be jumped to
Answers: 2
question
Computers and Technology, 23.06.2019 23:30
The keyboard usually has six rows of keys. which of the following is not one of the key group categories? letter keys number keys control keys graphic keys
Answers: 1
You know the right answer?
5.29 LAB: Replacement words
Write a program that replaces words in a sentence. The input begin...
Questions
question
Social Studies, 27.05.2021 09:10
question
Chemistry, 27.05.2021 09:10
question
Mathematics, 27.05.2021 09:10
question
Arts, 27.05.2021 09:10
question
English, 27.05.2021 09:10
question
Mathematics, 27.05.2021 09:10