Rotation Check
PHP
Medium
3 views
Problem Description
Check if b is a rotation of a (case-sensitive). Print YES or NO.
Input Format
Two lines a and b.
Official Solution
<?php
$inputText=rtrim(stream_get_contents(STDIN));
if($inputText==='') exit;
$inputLines=preg_split('/\\R/', $inputText);
$a=$inputLines[0] ?? '';
$b=$inputLines[1] ?? '';
if(strlen($a)!==strlen($b)){ echo 'NO'; exit; }
$twice=$a.$a;
echo (strpos($twice,$b)!==false) ? 'YES' : 'NO';
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!