Algoritmy “count” a “count_if”

{“https:\/\/www.jdoodle.com\/a\/bSR?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nvector<int> data = { 1, 2, 4 ,2, 4, 6 , 3, 2, 7, 2 };\n\nint main() {\n int cnt = count(data.begin(), data.end(), 2);\n cout << "Po\u010det v\u00fdskyt\u016f \u010d\u00edsla 2 je " << cnt << endl;\n return 0;\n}”,”https:\/\/www.jdoodle.com\/a\/bSN?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nvector<string> data = {\n "abcd",\n "abcdabc",\n "abcdabcdabcde",\n "ab",\n "abc",\n "abcdefe"\n};\n\n\/\/ Po\u010d\u00edt\u00e1 \u0159et\u011bzce del\u0161\u00ed ne\u017e hodnota length\nint countStrings(int length) {\n return count_if(data.begin(), data.end(), [length](string s) {\n return s.length() > length;\n });\n}\n\nvoid printCountOfStrings(int length, int count) {\n cout << "Po\u010det \u0159et\u011bzc\u016f del\u0161\u00edch ne\u017e " << length << " je " << count << "." << endl;\n}\n\nint main() {\n for(int length = 0; length < 10; length++) {\n int count = countStrings(length);\n printCountOfStrings(length, count);\n }\n return 0;\n}”}


Algoritmy “count” a “count_if”
Ohodnoťte tento článek