C++ String Rotation
 
This program accepts a string argument and returns an array of strings, which are shifted versions of the argument string.
* Featured post submitted and created by Padmanabhan.
C++
#include <iostream>
using namespace std;
void StringRotator(string s, int len);
int main() {
    string s;
    //Getting Input
    cin>>s;
    if(s. length()!=0)
    {
        cout<<"[";
        StringRotator(s,s.length());
        cout<<"]";
    }
    else
        cout<<"Sorry! No input is given";
    return 0;
}
void StringRotator(string s,int len)
{    
    static int i=0;
    cout<<"\"";
    for(int j=i;j<len;++j)
    {
        cout<<s.at(j);
    }
    for(int k=0;k<i;++k)
    {
        cout<<s.at(k);
    }
    cout<<"\"";
    i++;
    if(i<len)
    {
        cout<<endl;
        StringRotator(s,len);
    }
}
 
Comments
Post a Comment