Count Positive Numbers
PHP
Easy
4 views
Problem Description
You get n and then n integers. Count how many are > 0.
Input Format
First n. Next line n integers.
Output Format
One integer count.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$tokens=preg_split('/\\s+/', $inputText);
$i=0; $n=intval($tokens[$i++] ?? 0);
$c=0;
for($k=0;$k<$n;$k++) if(intval($tokens[$i++] ?? 0)>0) $c++;
echo $c;
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!