-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotate String
More file actions
46 lines (39 loc) · 744 Bytes
/
Rotate String
File metadata and controls
46 lines (39 loc) · 744 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
#include<iostream>
#include<cstring>
using namespace std;
void rotate(char a[],int n)
{ //1. move every character every one posn ahead
int len=strlen(a);
int i=len-1;
//cout<<a<<endl;
while(i>=0)
{
a[i+n]=a[i];
i--;
}
//cout<<a<<endl;
//step 2.
i=0;
int j=len;
while(i<n)
{
a[i]=a[j];
i++;
j++;
}
// cout<<a<<endl;
//step 3 . delete last n characters
a[len]='\0';
// cout<<a<<endl;
}
int main()
{
char a[100];
cin.getline(a,100);
int n;
cin>>n ; // no. of rotation we want to do;
cout<<"before rotation:"<<a<<endl;
rotate(a,n);
cout<<"after roatation:"<<a<<endl;
return 0;
}