fork(7) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int kasowaczka_spacji(string &kot,int j)
  6. {
  7. if (kot[j] != 32) return 0;
  8. else
  9. {
  10. kot.erase(kot.begin()+j);
  11. kasowaczka_spacji(kot, j);
  12. }
  13. }
  14.  
  15. int main()
  16. {
  17. string tekst;
  18. int flaga = 0; // jeżeli 1 to była spacja i następna literka idzie na dużą
  19. while (getline(cin, tekst))
  20. {
  21. if (tekst[0] == 32)
  22. {
  23. kasowaczka_spacji(tekst, 0);
  24. if (islower(tekst[0])) tekst[0] = toupper(tekst[0]);
  25. }
  26.  
  27. for (int i = 1; i < tekst.length(); i++)
  28. {
  29. if (flaga == 1 && tekst[i-1] >= 97 and tekst[i-1] <= 122) // check if char is lowercase
  30. {
  31. tekst[i-1]=toupper(tekst[i-1]);
  32. flaga = 0;
  33. if (tekst[i] == 32) // check if char is space
  34. {
  35. kasowaczka_spacji(tekst, i); //tekst.erase(tekst.begin()+i);
  36. flaga = 1;
  37. }
  38. }
  39. else if (flaga == 1 && tekst[i - 1] >= 65 and tekst[i - 1] <= 90) // check if char is uppercase
  40. {
  41. flaga = 0;
  42. }
  43. else if (tekst[i] == 32) // check if char is space
  44. {
  45. kasowaczka_spacji(tekst, i); //tekst.erase(tekst.begin()+i);
  46. flaga = 1;
  47. if (i == tekst.length()-1 && flaga == 1) tekst[i] = toupper(tekst[i]);
  48. }
  49.  
  50. }
  51.  
  52. for (int i = 0; i < tekst.length(); i++)
  53. {
  54. cout << tekst[i];
  55. }
  56. cout << endl;
  57. }
  58. return 0;
  59. }
Success #stdin #stdout 0s 15240KB
stdin
Dzisiaj jest czwartek,
A jutro bedzie piatek.
stdout
DzisiajJestCzwartek,
AJutroBedziePiatek.