Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int sub_vector(vector<int> source, vector<int> sub) {
- if (sub.size() > source.size()) return -1;
- for (int i = 0; i < source.size() - sub.size() + 1; ++i) {
- bool found = true;
- for (int j = 0; j < sub.size(); ++j) {
- if (sub[j] != source[i + j]) {
- found = false;
- break;
- }
- }
- if (found) {
- return i;
- }
- }
- return -1;
- }
- int main() {
- vector<int> source = {1,2,3,4,5};
- vector<int> sub = {1,2,3,4,5};
- cout << sub_vector(source, sub) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement