fork download
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std;
  4.  
  5. void EvenOddWords(std::istream& src, std::ostream& evenWords, std::ostream& oddWords)
  6. {
  7. std::string word;
  8.  
  9. while (src >> word) {
  10. evenWords << word << ' ';
  11. if (src >> word)
  12. oddWords << word << ' ';
  13. else
  14. break;
  15. }
  16. }
  17.  
  18. void EvenOddWords(const std::string& src, std::string& evenWords, std::string& oddWords)
  19. {
  20. std::ostringstream evenStream, oddStream;
  21. std::istringstream srcStream(src);
  22. EvenOddWords(srcStream, evenStream, oddStream);
  23. evenWords = evenStream.str();
  24. oddWords = oddStream.str();
  25. }
  26.  
  27. int main() {
  28. std::string line;
  29.  
  30. while(getline(cin, line)) {
  31. std::string even, odd;
  32. EvenOddWords(line, even, odd);
  33. cout << "------------------------------" << endl;
  34. cout << even << '!' << endl;
  35. cout << odd << '!' << endl;
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0s 3468KB
stdin
oneWord
    
Two words
1   2  3   4   5 	6
stdout
------------------------------
!
!
------------------------------
oneWord !
!
------------------------------
!
!
------------------------------
Two !
words !
------------------------------
1 3 5 !
2 4 6 !