File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* **************************************************************************
2
+
3
+ A Program to check if strings are rotations of each other or not.
4
+
5
+ ***************************************************************************/
6
+
7
+ SOLUTION (in C++):
8
+
9
+
10
+ Suppose there are two strings s1 = "devincept" and s2 = "vinceptde",
11
+
12
+ to check if s2 is rotation of s1, what we can do is string result = s1 + s1
13
+
14
+ and see if s2 is a substring of s1.
15
+
16
+
17
+ #include < bits/stdc++.h>
18
+
19
+ using namespace std ;
20
+
21
+ int main ()
22
+ {
23
+ string s1, s2, s3;
24
+ cout<<" Enter the strings" <<endl;
25
+ cin>>s1;
26
+ cin>>s2;
27
+ s3 = s1 + s1;
28
+ if (s3.find (s2) != -1 && s1 != s2)
29
+ {
30
+ cout<<s2<<" is rotation of " <<s1;
31
+ }
32
+ else
33
+ {
34
+ cout<<s2<<" is not rotation of " <<s1;
35
+ }
36
+ return 0 ;
37
+ }
You can’t perform that action at this time.
0 commit comments