fork(3) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string encrypted, decrypted;
  8. while (getline(cin,encrypted))
  9. {
  10. int j = 0;
  11. int n = 0;
  12. if (encrypted.size() == 1)
  13. {
  14. cout << encrypted << endl;
  15. encrypted.clear();
  16. continue;
  17. }
  18. while (encrypted[n] != ' ')
  19. {
  20. n++;
  21. j++;
  22. }
  23. for (int i = 0,t=0;i < n;i++)
  24. {
  25. decrypted += encrypted[i];
  26. t++;
  27. if ((encrypted[j] == ' ') && (encrypted[j + 1] == ' ')&&(j<encrypted.length()-1))
  28. {
  29. decrypted += ' ';
  30. t++;
  31. j += 2;
  32. continue;
  33. }
  34. else if (encrypted[j] == ' ') { j++; }
  35. while ((encrypted[j] != ' ')&&(j<encrypted.length()))
  36. {
  37. decrypted += encrypted[j];
  38. t++;
  39. j++;
  40. }
  41. decrypted += ' ';
  42. }
  43. while(decrypted.back() == ' ')decrypted.erase(decrypted.end()-1);
  44. cout << decrypted << endl;
  45. decrypted.clear();
  46. }
  47. return 0;
  48. }
Success #stdin #stdout 0s 4324KB
stdin
AMK LA A OTA
BIL OLEK  OLEK
EWWLPRK NIGMA  ERSJI IGHT O AZ OLEJNY
stdout
ALA MA KOTA
BOLEK I LOLEK
ENIGMA W WERSJI LIGHT PO RAZ KOLEJNY