Algoritmy “search” a “search_n”

{“https:\/\/www.jdoodle.com\/a\/clv?format=text”:”#include <iostream>\n#include <string>\n#include <algorithm>\nusing namespace std;\n\nint main() {\n string s1 = "Hello, world !!!!!";\n string s2 = "wor";\n auto it = search(s1.begin(), s1.end(), s2.begin(), s2.end());\n if(it == s1.end()) {\n cout << "Nenalezeno" << endl;\n } else {\n cout << "Pod\u0159et\u011bzec za\u010d\u00edn\u00e1 na indexu: " << distance(s1.begin(), it) << endl;\n }\n return 0;\n}”,”https:\/\/www.jdoodle.com\/a\/clr?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename Iterator>\nvoid print_n(Iterator it, int n) {\n while(n– > 0) {\n cout << *it << ";";\n it++;\n }\n cout << endl;\n}\n\nvector<int> data = {1, 2, 7, 4, 6, 10, 4, 3, 1 };\n\nint main() {\n \/\/ Najdi podposloupnost 4 cisel delitelnych dvema\n auto it = search_n(data.begin(), data.end(), 4, 2, [](int val, int divisibleBy){\n return val % divisibleBy == 0; \n });\n print_n(it, 4);\n return 0;\n \n}”}


Algoritmy “search” a “search_n”
Ohodnoťte tento článek