02. Furniture | Regular Expressions - Exercise | PHP, C#, JS or JAVA
02. Furniture - https://judge.softuni.bg/Contests/Practice/Index/1343#1
Някой който е рещавал задачата? Най вероятно регекса ми е грешен, не се сещам защо обаче. 80/100 до тук.
<?php
$re = '/[>]{2}(?<name>(([A-Z][a-z]+)|[A-Z]+|[A-Z][a-z]+[ ][a-z]+))[<]{2}(?<value>([0-9]+[.][0-9]+)|[0-9]+)[!](?<count>[0-9]+)\b/m';
$sum = 0.0;
$furnituresList = [];
while (true) {
$input = readline();
if ($input == "Purchase") { break; }
preg_match_all($re, $input, $matches, PREG_SET_ORDER, 0);
foreach($matches as $match) {
$furnituresList[] = $match["name"];
$sum += floatval($match["value"]) * floatval($match["count"]);
}
}
if ($sum > 0) {
echo "Bought furniture:" . PHP_EOL;
foreach ($furnituresList as $furniture) {
echo $furniture . PHP_EOL;
}
echo "Total money spend: " . number_format($sum, 2, ".", "");
}
?>