Advertisement
MeehoweCK

Untitled

Sep 30th, 2020
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // Napisz program, który pobiera od użytkownika jakiś tekst, a następnie wypisuje na ekran tylko parzyste znaki z tego tekstu,
  6. // ale w odwróconej kolejności
  7. // Przykład:
  8. // wejście: SAMOLOT
  9. // wyjście: OOA
  10.  
  11. string odwroc_tekst(string tekst)
  12. {
  13.     string wynik = "";
  14.  
  15.     for(int i = tekst.size() - 1; i >= 0; --i)
  16.         wynik += tekst[i];
  17.     return wynik;
  18. }
  19.  
  20. int main ()
  21. {
  22.     string tekst;
  23.  
  24.     cout << "Wpisz tekst: ";
  25.     cin >> tekst;
  26.     tekst = odwroc_tekst(tekst);
  27.  
  28.     unsigned i;
  29.     unsigned rozmiar = tekst.size();
  30.     if (rozmiar % 2 == 0)
  31.         i = 0;
  32.     else
  33.         i = 1;
  34.     for (; i < rozmiar; i += 2)
  35.         cout << tekst[i];
  36.     cout << endl;
  37.  
  38.     return 0;
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement