The common strings are Dallas Boston:
#include <iostream>
#include <vector>
using namespace std;
template<typename T>
vector<T> intersect(const vector<T>& v1, const vector<T>& v2) {
vector<T> vec;
for(int i = 0; i < v1.size(); ++i) {
for(int j = 0; j < v2.size(); ++j) {
if(v1[i] == v2[j]) {
vec.push_back(v2[j]);
break;
}
}
}
return vec;
}
int main() {
vector<string> v1;
v1.push_back("Atlanta");
v1.push_back("Dallas");
v1.push_back("Chicago");
v1.push_back("Boston");
v1.push_back("Denver");
vector<string> v2;
v2.push_back("Dallas");
v2.push_back("Tampa");
v2.push_back("Miami");
v2.push_back("Boston");
v2.push_back("Richmond");
vector<string> v3 = intersect(v1, v2);
cout << "The common strings are ";
for(int i = 0; i < v3.size(); ++i) {
cout << v3[i] << " ";
}
cout << endl;
return 0;
}
What is string?
A string is typically a sequence of characters in computer programming, either as a literal constant as some sort of variable. The latter can either be fixed or its elements and length can be altered (after creation). A string is commonly implemented as just an array data structure comprising bytes (or words) that contains a sequence of elements, typically characters, using some character encoding. A string is generally thought of as a type of data. A string can also represent various sequence(or list) data types and structures, such as more complex arrays. A variable declared as a string may enable memory storage to be statically allocated for a set maximum length or utilise dynamic allocation that allow it to retain a variable number of elements, appropriate programming language and specific data type used.
To learn more about string
brainly.com/question/25324400
#SPJ4