fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5.  
  6. void PrintArrays (const std::vector<std::vector<std::string>> items)
  7. {
  8. vector<int> indices;
  9. int n = items.size();
  10. indices.resize(items.size(),0);
  11.  
  12. while (true) //Iterate until we've used all of the last array of items
  13. {
  14. //Print
  15. for (int i = 0; i < n; ++i)
  16. {
  17. cout << items[i][indices[i]] << " ";
  18. }
  19. cout << endl;
  20.  
  21. //Update to the next indice
  22. for (int i = n - 1; i >= 0; --i)
  23. {
  24. indices[i] = (indices[i] + 1) % items[i].size();
  25. if (indices[i] != 0)
  26. {
  27. break;
  28. }
  29. else if (indices[i] == 0 && i == 0)
  30. {
  31. return; //Escape.
  32. }
  33. }
  34. }
  35.  
  36. }
  37.  
  38. int main() {
  39.  
  40. vector<vector<string>> lists;
  41.  
  42.  
  43. lists.resize(4);
  44. lists[0].push_back("AA");
  45. lists[0].push_back("BB");
  46. lists[1].push_back("CC");
  47. lists[2].push_back("DD");
  48. lists[2].push_back("EE");
  49. lists[2].push_back("FF");
  50. lists[3].push_back("GG");
  51.  
  52. PrintArrays(lists);
  53.  
  54. return 0;
  55. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
AA CC DD GG 
AA CC EE GG 
AA CC FF GG 
BB CC DD GG 
BB CC EE GG 
BB CC FF GG