D-Gj

Ciklichno pomestuvanje

Mar 3rd, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. // Da se izvrshi ciklichno pomestuvanje na tekst.
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     char text[500], shifted[500];
  11.     cout << "Vnesi tekst: ";
  12.     cin.getline(text, 500);
  13.  
  14.     int length = 0;
  15.  
  16.     do
  17.     {
  18.         length++;
  19.     } while (text[length] != '\0');
  20.  
  21.     cout << "Za kolku mesta da se pomesti tekstot? ";
  22.     int m;
  23.     cin >> m;
  24.  
  25.     if (m > length) m = length;
  26.  
  27.     cout << "Na kade da se pomesti tekstot (levo/desno)? ";
  28.     char direction[6];
  29.     cin >> direction;
  30.  
  31.     for (int i = 0; i < length; ++i)
  32.     {
  33.         if (strcmp(direction, "desno") == 0)
  34.             shifted[(i + m) % length] = text[i];
  35.         else
  36.             shifted[((i + length) - m) % length] = text[i];
  37.     }
  38.     shifted[length] = '\0';
  39.  
  40.     cout << shifted;
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment