[Programming Fundamentals] Regex - Exercises 4. Grocery Shop
Здравейте колеги,
Задачата ми дава 66/100. Това са моите регеглифи - (?<![: \t\w\S])[A-Z][a-z]+[:][0-9]+[.][0-9]{2}(?![\w\S]) . Мисля, че задачата ми дава проблем при имената на продуктите, тъй като сложих double.Parse на цените и задачата не гърми на тестовете. Най-вероятно съм изпуснал някой символ в регекса. Ще съм благодарен на едно рамо.
Това е решението ми - https://pastebin.com/f4yifi9j
4. Grocery Shop
You are given the task to write a program for a shop, which calculates the total price of products. The problem is the old system was full of bugs and you need to decrypt the data which you receive.
We know the following about the input data:
- The product name starts with English capital letter and all other letters should be lower-case.
- After that the product name should be followed by colon – ‘:’
- Price of the product, which should be floating point number with exactly two digits after the decimal point.
If you receive input, which does not follow the rules above - ignore it. If you receive new price for already existing product - rewrite the previous values.
At the end print the prices for every product. Order the products by price in descending order.
Input
You will receive indefinite count of string until you receive the command "bill".
Output
Print all prices ordered by price in descending order. Use the following format:
{nameOfTheProduct} costs {priceOfTheProduct}
Format the price to the 2nd decimal place.
Constraints
- The average prices will be in the interval [0.01…50.00]
Examples
Input |
Output |
Bread:12.31 bRead:41.31 Cola-12.31 Cola:12.31 Cola:14.23 bill |
Cola costs 14.23 Bread costs 12.31 |
Input |
Output |
Water:12.31 Water:12,42 Water:15.31 WaTer:30.20 Beer:15.12 bill |
Water costs 15.31 Beer costs 15.12 |