Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- static int call_cnt;
- static bool _is_concat(const char *const *list, size_t pos, size_t sz, const char *str)
- {
- call_cnt++;
- if (pos == sz)
- return false;
- if (!strlen(str))
- return true;
- const size_t l = strlen(list[pos]);
- if (strncmp(list[pos], str, l)) {
- return _is_concat(list, ++pos, sz, str);
- } else {
- if (_is_concat(list, 0, sz, str + l))
- return true;
- return _is_concat(list, ++pos, sz, str);
- }
- }
- static bool is_concat(const char *const *list, size_t sz, const char *str)
- {
- if (!str || !strlen(str))
- return false;
- return _is_concat(list, 0, sz, str);
- }
- int main(int argc, char **argv)
- {
- static const char *test_list[] = {
- "a", "b", "c", "d", "e", "f", "g", "h", "i"
- };
- size_t len = sizeof(test_list) / sizeof(test_list[0]);
- call_cnt = 0;
- printf("abcdefghiabcXdefghi: %d\n", is_concat(test_list, len, "abcdefghiabcXdefghi"));
- printf("call_cnt: %d\n", call_cnt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment