mirror of
https://github.com/mx42/codingame.git
synced 2026-01-14 05:39:51 +01:00
Adding medium/hard puzzles & challenges...
This commit is contained in:
29
puzzles/medium/telephone-numbers.php
Normal file
29
puzzles/medium/telephone-numbers.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// https://www.codingame.com/ide/puzzle/telephone-numbers
|
||||
// Xavier Morel - 2016-03-17
|
||||
|
||||
$maintab = array();
|
||||
$lines = (int) fgets(STDIN);
|
||||
$result = 0;
|
||||
|
||||
$i = 0;
|
||||
while ($i < $lines) {
|
||||
$nbr = fgets(STDIN);
|
||||
$nbr = trim($nbr);
|
||||
|
||||
$c = strlen($nbr);
|
||||
$tab = &$maintab;
|
||||
for ($j = 0; $j < $c; $j++) {
|
||||
$number = $nbr[$j];
|
||||
if (!isset($tab[$number])) {
|
||||
$tab[$number] = array();
|
||||
$result++;
|
||||
$tab =& $tab[$number];
|
||||
} else {
|
||||
$tab =& $tab[$number];
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
echo $result;
|
||||
Reference in New Issue
Block a user