Created
September 21, 2022 16:27
-
-
Save sanikamal/49544d2a9e817a70de882f5bbfe149a9 to your computer and use it in GitHub Desktop.
Given a string,S , of length N that is indexed from 0 to N-1 , print its even-indexed and odd-indexed characters as space-separated strings on a single line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$handle = fopen ("php://stdin","r"); | |
$t = fgets($handle); | |
for($i = 0; $i < $t; $i++) { | |
$input = trim(fgets($handle)); | |
$even = ''; | |
$odd = ''; | |
for($j = 0; $j < strlen($input); $j++) { | |
if(($j & 1) == 0) { | |
$even .= $input[$j]; | |
} | |
else { | |
$odd .= $input[$j]; | |
} | |
} | |
printf("%s %s\n", $even, $odd); | |
} | |
fclose($handle); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment