Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python-Advanced-Exercises , Lists as Stacks and Queues - Lab
- # https://judge.softuni.org/Contests/Practice/Index/1830#0
- # 01. Reverse Strings
- # 02. Matching Parentheses
- # 03. Supermarket
- # 04. Water Dispenser
- # 05. Hot Potato
- ================================================================================================================
- # 01. Reverse Strings
- data = list(input())
- while data:
- print(data.pop(), end='')
- ================================================================================================================
- # 02. Matching Parentheses
- expression = input()
- par_stack = []
- for index in range(len(expression)):
- if expression[index] == '(':
- par_stack.append(index)
- elif expression[index] == ')':
- start_index = par_stack.pop()
- print(expression[start_index:index+1])
- ================================================================================================================
- # 03. Supermarket
- from collections import deque
- name = input()
- line = deque()
- while not name == 'End':
- if name == 'Paid':
- while line:
- print(line.popleft())
- else:
- line.append(name)
- name = input()
- print(f'{len(line)} people remaining.')
- ================================================================================================================
- # 04. Water Dispenser
- from collections import deque
- liters = int(input())
- name = input()
- line = deque()
- while not name == 'Start':
- line.append(name)
- name = input()
- command = input()
- while not command == 'End':
- if command.isdigit():
- required_liters = int(command)
- name = line.popleft()
- if liters >= required_liters:
- liters -= required_liters
- print(f'{name} got water')
- else:
- print(f'{name} must wait')
- else:
- command = command.split()
- litters_to_fill = int(command[1])
- liters += litters_to_fill
- command = input()
- print(f'{liters} liters left')
- ================================================================================================================
- # 05. Hot Potato
- from collections import deque
- kids = deque(input().split())
- n = int(input())
- while len(kids) > 1:
- kids.rotate(-n)
- print(f"Removed {kids.pop()}")
- print(f'Last is {kids.pop()}')
- ================================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement