First Character Category
PHP
Easy
5 views
Problem Description
Given a string, look at the first character. Print DIGIT, LETTER, or OTHER.
Input Format
One line string s.
Output Format
One word category.
Official Solution
<?php
$s=stream_get_contents(STDIN);
$s=rtrim($s);
if($s==='') exit;
$ch=$s[0];
if(ctype_digit($ch)) echo 'DIGIT';
elseif(ctype_alpha($ch)) echo 'LETTER';
else echo 'OTHER';
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!