fork download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. const short SIZE = 257;
  7. int main(){
  8. int j = 0;
  9. char * str1 = new char[SIZE];
  10. char * str2 = new char[SIZE];
  11. cin.getline(str1, SIZE);
  12. int space = 0;
  13. for (int i = 0; i < strlen(str1); i++) {
  14. if (str1[i] == ' '){
  15. while (!space){
  16. str2[j] = ' ';
  17. j++;
  18. space = 1;
  19. }
  20. }
  21. else {
  22. str2[j] = str1[i];
  23. j++;
  24. space = 0;
  25. }
  26. }
  27. str2[j] = 0;
  28. printf("%s", str2);
  29. return 0;
  30. }
Success #stdin #stdout 0s 3416KB
stdin
              Иванов            Максим
stdout
 Иванов Максим