#include <algorithm> //std::sort
#include <iostream> //std::cout
#include <string> //std::string
#include <vector> //std::vector
std::vector<std::string> intersection(std::vector<std::string> &v1,
std::vector<std::string> &v2){
std::vector<std::string> v3;
std::sort(v1.begin(), v1.end());
std::sort(v2.begin(), v2.end());
std::set_intersection(v1.begin(),v1.end(),
v2.begin(),v2.end(),
back_inserter(v3));
return v3;
}
int main(){
std::vector<std::string> v1 {"a","b","c"};
std::vector<std::string> v2 {"b","c"};
auto v3 = intersection(v1, v2);
for(std::string n : v3)
std::cout << n << ' ';
}
Code Example |
---|
Cpp :: c++ cin |
Cpp :: minheap cpp stl |
Cpp :: recursive factorial of a number |
Cpp :: c++ program to convert fahrenheit to celsius |
Cpp :: c++ prime number |
Cpp :: c++98 check if character is integer |
Cpp :: inline function in cpp |
Cpp :: find an element in vector of pair c++ |
Cpp :: backtrack |
Cpp :: casting to a double in c++ |
Cpp :: find first of a grammar |
Cpp :: c++ sorting and keeping track of indexes |
Cpp :: string copy in cpp |
Cpp :: queue operations c++ |
Cpp :: copy vector c++ |
Cpp :: 1. Two Sum |
Cpp :: not c++ |
Cpp :: c++ last element of vector |
Cpp :: kmp c++ |
Cpp :: c++ shared pointer operator bool |
Cpp :: java to puthon converter |
Cpp :: even or odd program in c++ |
Cpp :: CPP print executable name |
Cpp :: how to create windows warning message c++ |
Cpp :: what is c++ |
Cpp :: how to print double value up to 9 decimal places in c++ |
Cpp :: Types of Triangles Based on Angles in c++ |
Cpp :: TCA9548 I2CScanner Arduino |
Cpp :: case 1 or 2 c++ |
Cpp :: what is blob in computer vision |