fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. void printTwoDString(vector< vector<string> > twodString){
  7. for(int i=0;i<twodString.size();i++){
  8. for(int j=0;j<twodString[i].size();j++)
  9. cout<<twodString[i][j]<<" ";
  10. cout<<endl;
  11. }
  12. }
  13.  
  14. int main() {
  15. vector< vector<string> > twodString={
  16. {"chandler", "joey", "janice"},
  17. {"gunther", "richard", "rachel"},
  18. {"monika", "phoebe","ross"}
  19. };
  20.  
  21. // sort the whole string
  22. std::sort(twodString.begin(), twodString.end());
  23. printTwoDString(twodString);
  24.  
  25. // sort a single row (should sort second row to gunther rachel richard )
  26. std::sort(twodString[1].begin(), twodString[1].end());
  27. cout<<endl;
  28. printTwoDString(twodString);
  29. return 0;
  30. }
Success #stdin #stdout 0s 15256KB
stdin
Standard input is empty
stdout
chandler joey janice 
gunther richard rachel 
monika phoebe ross 

chandler joey janice 
gunther rachel richard 
monika phoebe ross