• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Занятие 10. Functions and recursion

Difficulty level:

Task«Caching system»

The company develops software for scientific calculations. Many operations are performed repeatedly with the same parameters, which slows down the system. It is necessary to create a CACHEDCALCULATOR class, which will caching the results of mathematical operations. RN
The class must support four Operations: Addting (Add), Subtraction (Sub), Multiplication (Mul) and division (DIV). When repeatedly called the operation with the same parameters, the result should be taken from the cache. The class should conduct statistics on the number of operations performed and the number of appeals to the cache.
rn

Input format

The first line contains the number n-the number of operations. The following n lines contain operations in the format: "Operation Number1", where the operation is one of the Add, Sub, Mul, Div

Output format

the results of all operations in a sorted manner, each on a new line. Then the line with statistics in the format: "Operations: X, Cache Hits: Y", where X is the total number of operations, Y - the number of appeals to the Cash

Example

Input

6
Add 5 3
Mul 2 4
Add 5 3
Div 10 2
Mul 2 4
Sub 7 1

Output

5.0
6.0
8.0
8.0
8.0
8.0
Operations: 6, Cache Hits: 2

Hint

There will be no clue here, decide for yourself!

main.py
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Developer’s solution

🎉 Congratulations! 🎉

You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

AD

Advertisement

red-snake blue-snake green-snake

Running your code...

Помощник ИИ

Привет! Я твой помощник по программированию. Задавай любые вопросы по Python, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!