Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void moveElements(char[], int, int);
- int main() {
- int m, l;
- char str[100];
- cout << "str = ";
- cin.getline(str, 100);
- for (int i = 0; i <= 100; i++) {
- if ((int)str[i] < ' ' || str[i] > '~') {
- cout << "Error";
- }
- }
- cout << "M = ";
- cin >> m;
- if (m > 21 || m < 0) {
- cout << "Error";
- }
- cout << ", L = ";
- cin >> l;
- if (l > 100 || l < 0) {
- cout << "Error";
- }
- moveElements(str, m, l);
- return 0;
- }
- void moveElements(char str[], int m, int l) {
- int lastPossition = 0;
- char str2[100];
- for (int i = 0; i < 100; ++i) {
- if (str[i] == '\000') {
- lastPossition = i - 1;
- break;
- }
- int value = (int)str[i];
- str2[i] = str[i];
- if (value < 32 || value > 126 ||
- (str[i] == '\\' && (str[i + 1] == 'r' || str[i + 1] == 'n' || str[i + 1] == 't'))) {
- cout << str;
- return;
- }
- }
- for (int i = 0; i <= 100; ++i) {
- if (str[i] == '\000') {
- break;
- }
- char current = str[i];
- int toChangePossiton = 0;
- if (i + l <= lastPossition) {
- toChangePossiton = i + l;
- }
- else {
- toChangePossiton = ((i + l) - lastPossition) - 1;
- }
- char updeated = current + m;
- str2[toChangePossiton] = updeated;
- }
- cout << str2;
- }
Advertisement
Add Comment
Please, Sign In to add comment