fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Function to check if X can be derived from Y by rotating it
  5. bool check(string X, string Y)
  6. {
  7. return (X.length() == Y.length()) && ((X + X).find(Y) != string::npos);
  8. }
  9.  
  10. int main()
  11. {
  12. string X = "ABCD";
  13. string Y = "DABC";
  14.  
  15. if (check(X, Y))
  16. cout << "Given strings can be derived from each other";
  17. else
  18. cout << "Given strings cannot be derived from each other";
  19.  
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Given strings can be derived from each other