-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (37 loc) · 1.04 KB
/
main.cpp
File metadata and controls
49 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string rotateToLeft(string & word, int amount)
{
reverse(word.begin(),word.begin()+amount);
reverse(word.begin()+amount,word.end());
reverse(word.begin(), word.end());
return word;
}
string rotateToRight(string & word, int amount)
{
rotateToLeft(word,word.length()-amount);
return word; // if we are rotating reverse, just exract amount
}
string rotateTheString(string originalString, vector<int> direction, vector<int> amount) {
// 0 for left
// 1 for right
for (int i = 0; i < direction.size(); i++)
{
if(direction[i] == '0')
originalString=rotateToLeft(originalString, amount[i]);
else {
originalString= rotateToRight(originalString, amount[i]);
}
}
return originalString;
}
int main()
{
vector<int> direction;
direction.push_back(1);
vector<int> amount;
amount.push_back(2);
cout << rotateTheString("geeksforgeeks", direction, amount);
}