15,663,873 members

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

10

2 3 4 5 6 8 7 6 5 18

6

6 55

6 45

6 55

4 40

18 60

10 50

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

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

10

2 3 4 5 6 8 7 6 5 18

6

6 55

6 45

6 55

4 40

18 60

10 50

X = int(input()) # Number of shoes #10 #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 #6 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 print(p)

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

Staring at the computer for 1 hour 45 minutes trying to break the recursion down, slowly adding notes

Comments

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

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

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.