Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in C++ 3.1 Input The first line of input will be an integer N, representing the

ID: 3740548 • Letter: I

Question

in C++

3.1 Input The first line of input will be an integer N, representing the number of words, followed by another integer S, representing the amount to shift the words by, followed by a character representing the direction to shift the letters (either 'L' for left, or 'R' for right). Each word is no larger than 50 characters You can assume that the shift amount, S will not be larger than any of the words. Also, when a word is shifted, the letters at the start/end will move to the end/start, depending on the direction of the shift. For example, we will shift "loHe" by 3 to the left, and show each shift one at a time: Word | # of shift loHel oHell Hello 3 Shifts to the right behave similarly. 3.2 Output Your output should be each word shifted back to normal, followed by a single' Print the words in the order they appear in the input. 3.3 Sample Input/Output Sample Input Sample output Hello.Strange.Creatures. 3 3 L 11oHe ngeStra resCreatu

Explanation / Answer

// C program for Left Rotation and Right

// Rotation of a String

#include<bits/stdc++.h>

using namespace std;

// In-place rotates s towards left by d

void leftrotate(string &s, int d)

{

reverse(s.begin(), s.begin()+d);

reverse(s.begin()+d, s.end());

reverse(s.begin(), s.end());

}

// In-place rotates s towards right by d

void rightrotate(string &s, int d)

{

leftrotate(s, s.length()-d);

}

// Driver code

int main()

{

int a,b;

char c;

string str1, str2;

cin>>a;

cin>>b;

cin>>c;

for(int i=0;i<a;i++){

cin >> str1;

if(c=='l'){

leftrotate(str1,b);

str2.append(str1);

str2.append(".");

}

else if(c=='r'){

rightrotate(str1,b);

str2.append(str1);

str2.append(".");

}

}

cout<<str2;

return 0;

}