Strict Integer Parse
PHP
Medium
5 views
Problem Description
If the input is a valid integer text (optional sign, digits only) print the number, else print INVALID.
Input Format
One token s.
Output Format
Integer or INVALID.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
if(preg_match('/^[+-]?[0-9]+$/',$inputText)) echo intval($inputText);
else echo 'INVALID';
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!