#include <iostream>
#include <vector>
#include <string>
#include <iterator>
#include <sstream>
#include <algorithm>
using namespace std;

vector<int> str2vec (const string& s) {
	string s1{s};
	replace_if (s1.begin(), s1.end(), [](char c) { return c == ';'; }, ' ');
	vector<int> v;
	stringstream ss(s1);
	copy (istream_iterator<int>(ss), istream_iterator<int>(), back_inserter(v));
	
	return v;
}

typedef vector<int>::const_iterator iter;

iter approximate_find (const vector<int>& needle, const vector<int>& input, double prec=0) {
	iter i=input.cbegin();
	while (i < input.cend()-needle.size()) {
		bool found = true;
		for (iter j=needle.cbegin(); j != needle.cend(); ++j, ++i)
		   if (fabs (*i-*j) > *i*prec) {
		   	  found = false;
		   	  ++i;
		      break;
		   }
		if (found)
		   return i-needle.size();
	}
	return input.cend();
}

int main() {
	string input { "100;1000;10000;100000;900;75;871;347;" };
	vector<string> dictionary {
		 "77;15;224;34;781;574;1561;"
		,"800;8000;80000;850;"
		,"13;16;61;516;4;864;61;98;46;8189;63;"
	};
	
	vector<vector<int>> v_dic;
	transform (dictionary.begin(), dictionary.end(), back_inserter(v_dic), str2vec);
    vector<int> v_input = str2vec(input);
    
    for_each (v_dic.begin(), v_dic.end(), [&](const vector<int>& needle) {
    	iter i = approximate_find (needle, v_input, 0.2);
    	if (i != v_input.cend()) {
    	  copy (i, i+needle.size(), ostream_iterator<int>(cout, ";"));
   		  cout << " matches ";
    	}
    	else {
    		cout << "not found: ";
    	}
   	    copy (needle.begin(), needle.end(), ostream_iterator<int>(cout, ";"));
 	    cout << endl;
    });
}
