#include <iostream> #include <vector> using namespace std; int main(){ vector<st
ID: 3546886 • Letter: #
Question
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<string> friends{"Aisha Deaver", "Edmund Nazario", "Rayford Sabbagh",
"Leticia Esser", "Tam Looney", "Chris Fite", "Lauren Noah",
"Alfredo Treece", "Alda Colligan", "Nilsa Nance", "Ammie Saffell"};
vector<string> coworkers{"Nanci Moorehead", "Aisha Deaver", "Darius Meche",
"Alda Colligan", "Chris Fite", "Bernetta Ellman", "Lynna Deane",
"Leticia Esser", "Valeri Dolly", "Roberta Sensabaugh",
"Carmelita Stella"};
// please print the names of friends who are also coworkers using the most
// efficient way possible (a map?)
cout << "TODO ";
}
Explanation / Answer
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int main()
{
vector<string> friends;
friends.push_back("Aisha Deaver");
friends.push_back("Edmund Nazario");
friends.push_back("Rayford Sabbagh");
friends.push_back("Leticia Esser");
friends.push_back("Tam Looney");
friends.push_back("Chris Fite");
friends.push_back("Lauren Noah");
friends.push_back("Alfredo Treece");
friends.push_back("Alda Colligan");
friends.push_back("Nilsa Nance");
friends.push_back("Ammie Saffell");
vector<string> coworkers;
coworkers.push_back("Nanci Moorehead");
coworkers.push_back("Aisha Deaver");
coworkers.push_back("Darius Meche");
coworkers.push_back("Alda Colligan");
coworkers.push_back("Chris Fite");
coworkers.push_back("Bernetta Ellman");
coworkers.push_back("Lynna Deane");
coworkers.push_back("Leticia Esser");
coworkers.push_back("Valeri Dolly");
coworkers.push_back("Roberta Sensabaugh");
coworkers.push_back("Carmelita Stella");
vector<string> woring_friends;
sort(friends.begin(),friends.end());
sort(coworkers.begin(),coworkers.end());
set_intersection(friends.begin(), friends.end(),coworkers.begin(), coworkers.end(),back_inserter(woring_friends));
// please print the names of friends who are also coworkers using the most
// efficient way possible (a map?)
cout << "Common Working Friends are :" << endl;
for(vector<string>::iterator it =woring_friends.begin(); it!=woring_friends.end(); it++)
cout << *it << endl;
cout << endl;
/*
map<string, string> common_workers;
vector<string>::iterator it_worker =coworkers.begin();
for(vector<string>::iterator it =friends.begin(); it!=friends.end(),it_worker!=coworkers.end(); it++,it_worker++)
{
common_workers[*it] = *it_worker;
}
for( map<string,string>::iterator ii=common_workers.begin(); ii!=common_workers.end(); ++ii)
{
cout << (*ii).first << ": " << (*ii).second << endl;
string friend_s = (*ii).first;
string worker_s = (*ii).second;
if(friend_s.compare(worker_s)==0);
// cout << friend_s << endl;
}
//cout << "TODO ";
*/
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.