Task:
A string is given, no longer than 200,000 characters. It is necessary to print all the substrings (a successive sequence of characters within this string) using the set.
My solution logic is:
#include <iostream> #include <set> #include <cstring> #include <iterator> using namespace std; int main () { char s[200001] = {}; set <char*> mySet; cin >> s; int len = strlen(s); for (int i = 0; i < len; ++i) for (int j = 1; j <= len - i; ++j) { char s1[200001] = {}; strncpy(s1, s + i, j); mySet.insert(s1); } copy(mySet.begin(), mySet.end(), ostream_iterator<char*>(cout, " ")); return 0; } Problem:
Only 1 element is entered into the set (seemingly only the first substring, i.e. 'a')
Enter:
abba
Conclusion:
a
Should output:
a ab abb abba b bb bba ba
200000and squared ... can you imagine the amount of memory? 40 gigabytes or was I wrong? - pavel