fork download
  1. // recursiveTest.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include <string>
  5. #include <iostream>
  6. #include <vector>
  7. using namespace std;
  8.  
  9. void injectSpaces(vector<string>& wordsWithSpaces, vector<string>& words, vector<string>& spaces)
  10. {
  11. wordsWithSpaces.insert(wordsWithSpaces.end(), words.front());
  12. words.erase(words.begin());
  13.  
  14. if (words.size() == 0) return;
  15.  
  16. wordsWithSpaces.insert(wordsWithSpaces.end(), spaces.front());
  17. spaces.erase(spaces.begin());
  18.  
  19. injectSpaces(wordsWithSpaces, words, spaces);
  20. }
  21.  
  22. vector<string> injectSpaces(vector<string>& words)
  23. {
  24. vector<string> wordsWithSpaces;
  25. vector<string> spaces;
  26. spaces.insert(spaces.begin(), words.size(), " ");
  27.  
  28. injectSpaces(wordsWithSpaces, words, spaces);
  29. return wordsWithSpaces;
  30. }
  31.  
  32.  
  33. int main(int argc, char* argv[])
  34. {
  35. vector<string> words{ "i","need","some","spaces" };
  36.  
  37. for (string currWord : injectSpaces(words))
  38. {
  39. cout << currWord;
  40. }
  41.  
  42. int i; cin >> i;
  43. return 0;
  44. }
  45.  
  46.  
Success #stdin #stdout 0s 3240KB
stdin
Standard input is empty
stdout
i need some spaces