Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Da se izvrshi ciklichno pomestuvanje na tekst.
- #include <iostream>
- #include <cstring>
- using namespace std;
- int main()
- {
- char text[500], shifted[500];
- cout << "Vnesi tekst: ";
- cin.getline(text, 500);
- int length = 0;
- do
- {
- length++;
- } while (text[length] != '\0');
- cout << "Za kolku mesta da se pomesti tekstot? ";
- int m;
- cin >> m;
- if (m > length) m = length;
- cout << "Na kade da se pomesti tekstot (levo/desno)? ";
- char direction[6];
- cin >> direction;
- for (int i = 0; i < length; ++i)
- {
- if (strcmp(direction, "desno") == 0)
- shifted[(i + m) % length] = text[i];
- else
- shifted[((i + length) - m) % length] = text[i];
- }
- shifted[length] = '\0';
- cout << shifted;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment