std::string& string_b) {
30 const autosize_a = string_a.size();
31 const autosize_b = string_b.size();
32std::vector<std::vector<std::size_t>> sub_sols(
33size_a + 1, std::vector<std::size_t>(size_b + 1, 0));
35 const autolimit =
static_cast<std::size_t
>(-1);
36 for(std::size_t pos_a = size_a - 1; pos_a != limit; --pos_a) {
37 for(std::size_t pos_b = size_b - 1; pos_b != limit; --pos_b) {
38 if(string_a[pos_a] == string_b[pos_b]) {
39sub_sols[pos_a][pos_b] = 1 + sub_sols[pos_a + 1][pos_b + 1];
41sub_sols[pos_a][pos_b] = std::max(sub_sols[pos_a + 1][pos_b],
42sub_sols[pos_a][pos_b + 1]);
47 returnsub_sols[0][0];
55 conststd::string string_a;
56 conststd::string string_b;
57 conststd::size_t common_string_len;
59TestCase(std::string string_a, std::string string_b,
60 conststd::size_t in_common_string_len)
61: string_a(std::move(string_a)),
62string_b(std::move(string_b)),
63common_string_len(in_common_string_len) {}
76 TestCase(
"BADANA",
"CANADAS", 3),
77 TestCase(
"a1a234a5aaaa6",
"A1AAAA234AAA56AAAAA", 6),
90template<
typenameTestCases>
92 for(
const auto& cur_tc : test_cases) {
94cur_tc.common_string_len);
104template<
typenameTestCases>
107 for(
const auto& cur_tc : test_cases) {
109cur_tc.common_string_len);
120 return{in_str.rbegin(), in_str.rend()};
129template<
typenameTestCases>
132 for(
const auto& cur_tc : test_cases) {
135cur_tc.common_string_len);
144assert(test_cases.size() > 0);
149std::cout <<
"All tests have successfully passed!\n";
class encapsulating the necessary test cases
static void test_longest_common_string_length_for_reversed_inputs(const TestCases &test_cases)
checks if the function longest_common_string_length returns the same result when its inputs are rever...
static void tests()
runs all tests for longest_common_string_length funcion
std::vector< TestCase > get_test_cases()
static void test_longest_common_string_length(const TestCases &test_cases)
checks the function longest_common_string_length agains example data
std::size_t longest_common_string_length(const std::string &string_a, const std::string &string_b)
computes the length of the longest common string created from input strings
std::string reverse_str(const std::string &in_str)
reverses a given string
static void test_longest_common_string_length_is_symmetric(const TestCases &test_cases)
checks if the function longest_common_string_length returns the same result when its argument are fli...
int main()
Main function.
represents single example inputs and expected output of the function longest_common_string_length
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4