Word Count
PHP
Easy
5 views
Problem Description
Count how many words are in the string (words separated by spaces).
Input Format
One line string s.
Output Format
One integer count.
Official Solution
<?php
$inputText=rtrim(stream_get_contents(STDIN));
if($inputText==='') exit;
$inputText=trim($inputText);
if($inputText===''){ echo 0; exit; }
$parts=preg_split('/\\s+/', $inputText);
echo count($parts);
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!