File tree 1 file changed +51
-0
lines changed
1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ string stringShift (string s, vector<vector<int >>& shift) {
4
+ int left=0 ;
5
+ int right=0 ;
6
+ for (int i=0 ;i<shift.size ();i++){
7
+ if (shift[i][0 ]==0 ){
8
+ left+=shift[i][1 ];
9
+ }
10
+ else if (shift[i][0 ]==1 )
11
+ {
12
+ right+=shift[i][1 ];
13
+ }
14
+ }
15
+ int n=s.size ();
16
+ int x;
17
+ string final =" " ;
18
+ cout<<left<<" " <<right;
19
+ if (left>right){
20
+ x=left-right;
21
+ x=x%n;
22
+ string aage=" " ;
23
+ for (int i=x;i<n;i++){
24
+ aage+=s[i];
25
+ }
26
+ string piche=" " ;
27
+ for (int i=0 ;i<x;i++){
28
+ piche+=s[i];
29
+ }
30
+ final =aage + piche;
31
+ }
32
+ else {
33
+ x=right-left;
34
+ x=x%n;
35
+
36
+ string aage=" " ;
37
+ for (int i=n-x;i<n;i++){
38
+ aage+=s[i];
39
+ }
40
+ string piche=" " ;
41
+ for (int i=0 ;i<n-x;i++){
42
+ piche+=s[i];
43
+ }
44
+ final =aage + piche;
45
+ }
46
+ if (x==0 ){
47
+ return s;
48
+ }
49
+ return final ;
50
+ }
51
+ };
You can’t perform that action at this time.
0 commit comments