fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define withRL
  5.  
  6. int main() {
  7. string s;
  8. getline(cin , s);
  9. int i, j = 0;
  10. bool ifspace = false;
  11. for(i = 0; i < s.length(); i++){
  12. if(s[i] == ' '){
  13. #ifdef withRL
  14. if(!ifspace){
  15. #else
  16. if(j && !ifspace){
  17. #endif
  18. ifspace = true;
  19. s[j] = s[i];
  20. j++;
  21. }
  22. }
  23. else{
  24. ifspace = false;
  25. s[j] = s[i];
  26. j++;
  27. }
  28. }
  29. s.erase(j);
  30. if(s.back() == ' ') s.pop_back();
  31. cout << s << endl;
  32. }
Success #stdin #stdout 0s 3276KB
stdin
                                  Gagarin became    an international celebrity, and was                                           awarded many medals and titles, including Hero of the Soviet Union.       
stdout
Gagarin became an international celebrity, and was awarded many medals and titles, including Hero of the Soviet Union.