Count Integers and Floats

Count Integers and Floats

Medium PHP PHP Data Types 27 views
Explanation Complexity

Problem Statement

Given n numeric tokens, count how many look like integers vs floats (contains '.' or exponent).

Input Format

First n. Next line has n tokens.

Output Format

Two integers: intCount floatCount.

Example

6
1 2 3.5 4e2 -7 0.0
3 3

Constraints

n

Input / Output Format

Input Format
First n. Next line has n tokens.
Output Format
Two integers: intCount floatCount.
Constraints
n

Examples

Input:
6 1 2 3.5 4e2 -7 0.0
Output:
3 3

Example Solution (Public)

PHP
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$tokens=preg_split('/\\s+/', $inputText);
$i=0; $n=intval($tokens[$i++] ?? 0);
$ic=0; $fc=0;
for($k=0;$k<$n;$k++){
  $t=$tokens[$i++] ?? '';
  if($t==='' ) continue;
  if(preg_match('/[\\.eE]/',$t)) $fc++; else $ic++;
}
echo $ic.' '.$fc;
?>

Official Solution Code

<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$tokens=preg_split('/\\s+/', $inputText);
$i=0; $n=intval($tokens[$i++] ?? 0);
$ic=0; $fc=0;
for($k=0;$k<$n;$k++){
  $t=$tokens[$i++] ?? '';
  if($t==='' ) continue;
  if(preg_match('/[\\.eE]/',$t)) $fc++; else $ic++;
}
echo $ic.' '.$fc;
?>
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.