Search
 
SCRIPT & CODE EXAMPLE
 

CPP

https://www.geeksforgeeks.org/a-program-to-check-if-strings-are-rotations-of-each-other/

1. Create a temp string and store concatenation of str1 to
       str1 in temp.
                          temp = str1.str1
    2. If str2 is a substring of temp then str1 and str2 are 
       rotations of each other.

    Example:                 
                     str1 = "ABACD"
                     str2 = "CDABA"

     temp = str1.str1 = "ABACDABACD"
     Since str2 is a substring of temp, str1 and str2 are 
     rotations of each other.
Comment

https://www.geeksforgeeks.org/a-program-to-check-if-strings-are-rotations-of-each-other/

// C++ program to check if two given strings
// are rotations of  each other
# include <bits/stdc++.h>
using namespace std;
 
/* Function checks if passed strings (str1
   and str2) are rotations of each other */
bool areRotations(string str1, string str2)
{
   /* Check if sizes of two strings are same */
   if (str1.length() != str2.length())
        return false;
 
   string temp = str1 + str1;
  return (temp.find(str2) != string::npos);
}
 
/* Driver program to test areRotations */
int main()
{
   string str1 = "AACD", str2 = "ACDA";
   if (areRotations(str1, str2))
     printf("Strings are rotations of each other");
   else
      printf("Strings are not rotations of each other");
   return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: comment savoir si un nombre est premier c++ 
Cpp :: what is imposter syndrome 
Cpp :: cast unreal c++ 
Cpp :: left recursion program in c++ 
Cpp :: minimum no of jump required to reach end of arry 
Cpp :: changing key bindings in visual code not working 
Cpp :: arrays to function c++ 
Cpp :: gcd 
Cpp :: Chef and IPC Certificates codechef solution in c++ 
Cpp :: The iostream is the head er file which contains all the functions of program like cout, cin and etc. 
Cpp :: convert c++ program to c online 
Cpp :: Structure of s void function 
Cpp :: C++ 4.3.2 (gcc-4.3.2) sample 
Cpp :: user inptu in cpp 
Cpp :: tutti i tipi di equazioni trigonometriche 
Cpp :: lcm recursive program in c++ 
Cpp :: how to declare a function in c++ header file 
Cpp :: turn github into vscode 
Cpp :: how to code a segment tree in c++ 
Cpp :: c++ do you not inherit constructor 
Cpp :: std::string remove last 
Cpp :: hello world program in c ++ using standard namespace 
Cpp :: c++ how to skip the last element of vector 
C :: what is meaning of product *= in c 
C :: c string is int 
C :: printf boo; 
C :: Creating a process in C 
C :: printf signed char 
C :: c language append line to file 
C :: selection sort in c 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =