Reverse String Function

Reverse String Function

Easy PHP PHP Functions 31 views
Explanation Complexity

Problem Statement

Write a function reverseStr(s) and print the reversed string.

Input Format

One line string s.

Output Format

One line reversed.

Example

abcd
dcba

Constraints

|s|

Input / Output Format

Input Format
One line string s.
Output Format
One line reversed.
Constraints
|s|

Examples

Input:
abcd
Output:
dcba

Example Solution (Public)

PHP
<?php
$inputText=rtrim(stream_get_contents(STDIN));
if($inputText==='') exit;
function reverseStr($t){
  $out='';
  for($i=strlen($t)-1;$i>=0;$i--) $out.=$t[$i];
  return $out;
}
echo reverseStr($inputText);
?>

Official Solution Code

<?php
$inputText=rtrim(stream_get_contents(STDIN));
if($inputText==='') exit;
function reverseStr($t){
  $out='';
  for($i=strlen($t)-1;$i>=0;$i--) $out.=$t[$i];
  return $out;
}
echo reverseStr($inputText);
?>
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.