Click here to Skip to main content
15,667,536 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The Task is:

Raghu is a shoe shop owner. His shop has X number of shoes.
He has a list containing size of each shoe he has in his shop.
There are N number of customers, who are willing to pay xi amount of money only if they get the shoe of their desired size.
Your task is to compute, how much money Raghu earned.

Input Format
First line contains, X number of shoes.
Second line contains, space separated size of the shoes.
Third line contains, N number of customers.
Next N line contain, space separated values of shoe size and xi price of shoe.

The ACTUAL Input

2 3 4 5 6 8 7 6 5 18
6 55
6 45
6 55
4 40
18 60
10 50

X = int(input()) # Number of shoes

#Spliting the input and changing it to an integer
N = map(int,input().split()) #Space separated list of shoe sizes in shop

#Outcome will be ["2","3","4","5","6","8","7","6","5","18"]

x = int(input()) # Number of customers

L = map(tuple,(map(int,input().split()) for _ in range(x)))

# Take the shoe size and price of shoe for every customer for amount of customers
# and then convert to list of ints
# Then make them a Tuple
# Outcome will be (6, 55, 6, 45, 6, 55, 4, 40, 18, 60, 10, 50)

n = Counter(N)
# n {
  #  2: 1,
  #  3: 1,
  #  4: 1,     # -1 Subtracted in iteration
  #  5: 2,
  #  6: 2,     # -1 Subtracted in iteration(twice)
  #  8: 1,
  #  7: 1,
  #  18: 1,    # -1 Subtracted in iteration

p = 0          # counter to add/subtract to

for i in L:
    if i[0] in n.keys() and n[i[0]] > 0 :
        n[i[0]] = n[i[0]]-1
    # Subtracts from key if item matches from L(is immutable tuple)
        p = p+i[1] # + 55, + 45, + 40, + 60
    #Since iterating through ALL L, one by one, Index i[1] would be next in list L

Am I understanding this recursion correctly? The part I am having trouble understanding is how p is incrementing at index 1. Is this PURELY because of the line ***for i in L*** which makes it Iterate through the ENTIRE LIST starting the index over for each item?

I would love some clarification for my notes. <3

What I have tried:

Staring at the computer for 1 hour 45 minutes trying to break the recursion down, slowly adding notes
Updated 15-Aug-22 19:47pm
Richard MacCutchan 16-Aug-22 4:02am    
If you take the list of sizes and prices then the money earned will be the total of all prices for a shoe size that exists. However, that seems too simple, so I believe there is some information missing from the question.
Chris Aug2022 16-Aug-22 22:35pm    
..... Second line contains, space separated size of the shoes. AVAILABLE
AKA these are the sizes in stock.. 2 3 4 5 6 8 7 6 5 18

#Spliting the input and changing it to an integer
N = map(int,input().split()) #Space separated list of shoe sizes in shop

I thought you were a noob when you answered but I looked at your profile and realized you just didn't read the code and notes AT ALL. LIke damn man. C'mon. Go on, go talk about how this or that should be here or there. But if you read the code you would've known.
Richard MacCutchan 17-Aug-22 3:29am    
Yes, I did read the notes, and I do understand the list of shoe sizes. What I don't understand is what you are supposed to calculate given 6 customers and six shoe prices.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900