Search
 
SCRIPT & CODE EXAMPLE
 

CPP

a program to check if strings are rotations of each other or not

#include<iostream>
#include<string>
using namespace std;

bool rRotation(string str1, string str2)
{
    int len1= str1.length(), len2 = str2.length();
    int j=0,i;
    for(i=0; i<len1; i++)
    {
        if(str1[i]==str2[j])
        {
            break;
        }
    }
    while(j<len2)
    {
        i = i % str1.length();
        if(str1[i] == str2[j])
        {
            i++;
            j++;
        }
        else
        {
            //cout<<"not Rotation"<<endl;
            return false;
        }
    }
    //cout<<"Rotation"<<endl;
    return true;
}

int main()
{
    string str1, str2;
    cin>>str1;
    cin>>str2;
    //rRotation(str1, str2);
    cout<<rRotation(str1, str2);
    return 0;
}
/*
ABCD
BCDA
1
*/
Comment

PREVIOUS NEXT
Code Example
Cpp :: know what the input data is whether integer or not 
Cpp :: unique element in array in c 
Cpp :: pointer to pointer c++ 
Cpp :: sort an array in c++ 
Cpp :: long long vs long long int 
Cpp :: min heap 
Cpp :: max and min function in c++ 
Cpp :: remove elements from vector 
Cpp :: c++ stl 
Cpp :: pragma HLS bracets 
Cpp :: check if cin got the wrong type 
Cpp :: pthread c++ example with output 
Cpp :: largest subarray with zero sum 
Cpp :: wgat is duble in c++ 
Cpp :: how to scan vector in c++ 
Cpp :: print all variables separated by comma c++ 
Cpp :: find no of occurences of each letter in string c++ 
Cpp :: Mirror Inverse Program in c++ 
Cpp :: how to code a game in c++ 
Cpp :: function and function prototype. 
Cpp :: pointers mcq sanfoundry 
Cpp :: +905344253752 
Cpp :: sjfoajf;klsjflasdkfjk;lasjfjajkf;dslafjdjalkkkjakkkkkkkkkkkkkkkkfaWZdfbhjkkkk gauds 
Cpp :: std::copy 
Cpp :: vermífugo significado 
Cpp :: formated string std::cout 
Cpp :: c++ poitner 
Cpp :: GCD(x, yz) 
Cpp :: Explicit conversion casting 
Cpp :: initialize many variablles c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =