14811 - Varaha   

Description

Varaha is very hungry

He wants you to go buy him some groceries.

As an I2P student, you have to make a shopping list to buy the foods for Varaha.
                              
                                                             The secret of the two appearances of Lord Varāhadeva
 

Write a program to manage a shopping list. Each item in the list has a name and a quantity.

 

The program should support the following commands:

  • add → Add an entry with a quantity. If the entry already exists, increase its quantity.

  • remove → Remove a quantity of an entry. If the quantity becomes 0 or negative, remove the entry completely.

  • show → Display the current shopping list

  • count → Print the total sum of all quantities in the list.

  • clear → Remove all entries from the shopping list.

 

items = {}

# Functions
def add():
    pass

def remove():
    pass

def show():
    pass

def count():
    pass

def clear():
    pass

# Command mapping using lambdas
actions = {
    # todo
}

# Main program
n = int(input())
for _ in range(n):
    cmd = input().strip()

    # todo

Input

  • The first line contains an integer n ,number of commands.

  • The next n lines contain the commands

 

For add and remove, the next line contains the entry name and quantity separated by a space.

For show, count, and clear, no additional input is required.

Output

  • show, print the shopping list.

  • count, print the total sum of quantities.

  • No output is required for add, remove, or clear.

Sample Input  Download

Sample Output  Download




Discuss