-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathstring_rotation.cpp
67 lines (59 loc) · 1.03 KB
/
string_rotation.cpp
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
57
58
59
60
61
62
63
64
65
66
67
/*
String Rotation
input
career
3
L 2
R 3
L 2
output
NO
*/
#include <string.h>
#include <iostream>
using namespace std;
string shiftLeft(char* s)
{
int len = strlen(s);
std::string st = ((string)s).substr(1, len-1);
return st+s[0];
}
string shiftRight(char* s)
{
int len = strlen(s);
std::string st = ((string)s).substr(0, len-1);
return s[len-1]+st;
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
char str[200],ch;
int q,m;
string firstchar="";
cin>>str;
cin>>q;
for(int i=0;i<q;i++)
{
cin>>ch>>m;
if(ch=='L')
{
for(int j=0;j<m;j++)
{
firstchar+=shiftLeft(str)[0];
}
}
else if(ch=='R')
{
for(int j=0;j<m;j++)
{
firstchar+=shiftRight(str)[0];
}
}
}
cout<<firstchar;
if (((string)str).find(firstchar) != std::string::npos) {
cout << "YES";
}
else
cout<<"NO";
return 0;
}