-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotate_string_by_two.cpp
More file actions
56 lines (40 loc) · 1018 Bytes
/
Rotate_string_by_two.cpp
File metadata and controls
56 lines (40 loc) · 1018 Bytes
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
50
51
52
53
54
55
56
#include<iostream>
#include<string>
using namespace std;
void rotateclockwise(string &s) {
char c = s[s.size()-1];
int index = s.size() -2;
while(index >= 0) {
s[index+1] = s[index];
index --;
}
s[0] = c;
}
void rotateanticlockwise(string &s) {
char c = s[0];
int index = 1;
while(index < s.size()) {
s[index-1] = s[index];
index++;
}
s[s.size()-1] = c;
}
int main() {
string str1 = "amazon";
string str2 = "azonam";
string clockwise = str1;
string anticlockwise = str1;
rotateclockwise(clockwise);
rotateclockwise(clockwise);
if(clockwise == str2){
cout<<"clockwise";
return 1;
}
rotateanticlockwise(anticlockwise);
rotateanticlockwise(anticlockwise);
if(anticlockwise == str2){
cout<<"anticlockwise";
return 1;
}
cout << "no match";
}