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, 21.06.2019 17:00
The most efficient way to establish top best possible economize position is to measure
Answers: 1
question
Computers and Technology, 22.06.2019 07:00
You will be given two character arrays of the same size, one will contain a number of ships. ships will move around the character array based on which way they are facing and the route they are on. routes are given in the other array. the route consists of '-' and '|' for straight paths, '\' and '/' for curves, and '+' for intersections. there are ships on these routes. ships always face a direction, '^' for up, '> ' for right, 'v' for down, and '< ' for left. any time the ships hit a '\' or a '/' it will turn as you would expect a ship to turn (e.g. a '^' that moves into a '/' will turn right). at an intersection, ships will always continue straight through. all ships move at the same speed, ships take turns moving and all ships move during one 'tick'. the one in the most top left goes first, followed by those to its right, then the ones in the next row. it iterates along the rows and then down the columns. each ship moves one space on its turn moving along the route. your function needs to return the position of the first collision between two ships and the number of ticks before the crash occurred.
Answers: 2
question
Computers and Technology, 22.06.2019 10:40
5. illustrate how fine-line inventory classification can be used with product and market segments. what are the benefits and considerations when classifying inventory by product, market, and product/market?
Answers: 2
question
Computers and Technology, 22.06.2019 15:00
Hyperactive media sales has 10 windows 7 laptop computers used by sales-people in the organization. each laptop computer has several customized applications that are used during the sales process as well as customer relationship management software. all of the applications on the laptops are difficult to configure and have large data files. if all of the laptops have current hardware, what is the easiest way to install windows 10 on them?
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
History, 24.07.2019 15:30
question
Biology, 24.07.2019 15:30
Questions on the website: 13722363