36.9k views
3 votes
Integer numElements is read from input. Then, numElements strings are read and stored in vector aprTopPicks, and numElements strings are read and stored in vector novTopPicks. Perform the following tasks:

If aprTopPicks is equal to novTopPicks, output "November's top picks are the same as April's top picks." Otherwise, output "November's top picks are not the same as April's top picks."

Assign novBackup as a copy of novTopPicks.

Ex: If the input is 2 brick gold red green, then the output is:

April's top picks: brick gold
November's top picks: red green
November's top picks are not the same as April's top picks.
November's backup: red green
in c++

2 Answers

3 votes

Answer:

c++

Step-by-step explanation:

User JJK
by
7.4k points
4 votes

Answer:

#include <iostream>

#include <vector>

#include <algorithm>

int main() {

int numElements;

std::cin >> numElements;

std::vector<std::string> aprTopPicks(numElements);

for (int i = 0; i < numElements; i++) {

std::cin >> aprTopPicks[i];

}

std::vector<std::string> novTopPicks(numElements);

for (int i = 0; i < numElements; i++) {

std::cin >> novTopPicks[i];

}

if (aprTopPicks == novTopPicks) {

std::cout << "November's top picks are the same as April's top picks." << std::endl;

} else {

std::cout << "November's top picks are not the same as April's top picks." << std::endl;

}

std::vector<std::string> novBackup(numElements);

std::copy(novTopPicks.begin(), novTopPicks.end(), novBackup.begin());

std::cout << "April's top picks: ";

for (int i = 0; i < numElements; i++) {

std::cout << aprTopPicks[i] << " ";

}

std::cout << std::endl;

std::cout << "November's top picks: ";

for (int i = 0; i < numElements; i++) {

std::cout << novTopPicks[i] << " ";

}

std::cout << std::endl;

std::cout << "November's top picks are ";

if (aprTopPicks == novTopPicks) {

std::cout << "the same as ";

} else {

std::cout << "not the same as ";

}

std::cout << "April's top picks." << std::endl;

std::cout << "November's backup: ";

for (int i = 0; i < numElements; i++) {

std::cout << novBackup[i] << " ";

}

std::cout << std::endl;

return 0;

}

Step-by-step explanation:

User Raggaer
by
7.5k points