alphacademy-cpp/archive/hf16/3.cpp

27 lines
559 B
C++
Raw Normal View History

2022-05-21 12:30:25 +00:00
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// harmadik feladat
vector<int> common(vector<int> a, vector<int> b) {
vector<int> out;
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < b.size(); j++) {
if (a[i] == b[j]) {
out.push_back(a[i]);
}
}
}
return out;
}
int main() {
vector<int> a = {1,2,3,4,5,6};
vector<int> b = {2,4,6,8,10};
vector<int> out = common(a,b);
for (int i = 0; i < out.size(); i++) {
cout<<out[i]<<" ";
}
}