5.29 LAB: Replacement words
Write a program that replaces words in a sentence. The input begin...
Computers and Technology, 29.05.2020 07:58, payshencec21
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.
Answers: 2
Computers and Technology, 21.06.2019 21:00, brockmorrison3468
Is it ok to use a does red wine clean the inside of a computer true or false
Answers: 2
Computers and Technology, 22.06.2019 10:00, QueenKy9576
Wich technology can a website use to allow you to listen to a concert live over the internet?
Answers: 3
Computers and Technology, 23.06.2019 22:40, azariah7
22. sata3 allows for data transfer rates of 600 mb/s. explain why you would likely not be able to copy data from one hard drive to another at anywhere close to this speed. also, what could be upgraded on the computer to achieve transfer speeds closer to 600 mb/s
Answers: 1
Mathematics, 29.06.2019 02:30
Biology, 29.06.2019 02:30
Biology, 29.06.2019 02:30
Social Studies, 29.06.2019 02:30
Biology, 29.06.2019 02:30
English, 29.06.2019 02:30