fork download
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. string s = "";
  11. int k = -1;
  12. int a = 0;
  13. int b = 1;
  14. int c = 2;
  15. std::vector <string> list;
  16.  
  17. cout << "Введите строку: ";
  18. cin >> s;
  19.  
  20. cout << "Введите длину сочетания: ";
  21. cin >> k;
  22.  
  23. while (a <= s.length() - k) {
  24. b = a + 1;
  25. while(b <= s.length() - k + 1) {
  26. c = b + 1;
  27. while (c <= s.length() - k + 2) {
  28.  
  29. string item = s.substr(a, 1) + s.substr(b, 1) + s.substr(c, k - 2);
  30. if (find(list.begin(), list.end(), item) == list.end())
  31. list.push_back(item);
  32. c++;
  33. }
  34. b++;
  35. }
  36. a++;
  37. }
  38.  
  39. for (int i = 0; i < list.size(); i++)
  40. cout << list[i] << ' ';
  41. }
Success #stdin #stdout 0s 4500KB
stdin
aaabbbcc 4
stdout
Введите строку: Введите длину сочетания: aaab aabb aabc aacc abbb abbc abcc bbbc bbcc