Big Integer Comparison
PHP
Hard
5 views
Problem Description
Compare two big non-negative integers given as strings. Print , or =.
Input Format
One line: a b.
Output Format
One character.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
[$a,$b]=preg_split('/\\s+/', $inputText, 2);
$a=ltrim($a,'0'); if($a==='') $a='0';
$b=ltrim($b,'0'); if($b==='') $b='0';
if(strlen($a)<strlen($b)) echo '<';
elseif(strlen($a)>strlen($b)) echo '>';
else{
if($a===$b) echo '=';
elseif($a<$b) echo '<';
else echo '>';
}
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!