-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_most_frequent_main.cpp
More file actions
40 lines (36 loc) · 1.08 KB
/
find_most_frequent_main.cpp
File metadata and controls
40 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
6 kyu
Find most frequent element in a list
https://www.codewars.com/kata/59b1314d44a4b7b93b000073
*/
#include <forward_list>
#include <iostream>
#include <utility>
std::pair<int, int> findMostFrequent(const std::forward_list<int>& l);
static void do_test(const std::forward_list<int>& l,
const std::pair<int, int>& expected) {
std::pair<int, int> actual = findMostFrequent(l);
std::cout << "expected: " << expected.first << ", " << expected.second
<< std::endl;
std::cout << "actual : " << actual.first << ", " << actual.second
<< std::endl;
std::cout << (expected == actual ? "OK" : "FAIL") << std::endl << std::endl;
}
int main() {
{
std::forward_list<int> l = {1, 2, 3, 4, 2, 3, 2};
std::pair<int, int> expected = {2, 3};
do_test(l, expected);
}
{
std::forward_list<int> l = {4, 3, 5, 3, 4, 5};
std::pair<int, int> expected = {4, 2};
do_test(l, expected);
}
{
std::forward_list<int> l = {1, 2, 3, 4, 3, 5, 5, 3};
std::pair<int, int> expected = {3, 3};
do_test(l, expected);
}
return 0;
}