The Gocargo are automating their testing works of the logistics wing too. They have planned to test if the container loading works correctly or not.
Given the process involved in loading, in the form of expression, evaluate if the container loader has worked correct or not.
Conventions
'{' for cargos, '[' for containers and '(' for boxes.
Rules:
* cargo cannot be inside another cargo or container or box.
* container cannot be inside another container or box.
* box can be inside another box.
Please check whether the container loader has worked correctly.
Sample Input 1 :
{[2+3+4+(2+1)+4+(2+4)]+[3+4]}+{[2+4+5]}
Sample Output 1:
Valid
Sample Input 2 :
{[2+3+4+(2+1)+4+(2+4)]+3+4]}+{[2+4+5]}}
Sample Output 2:
Invalid
Explanation for sample 1:
There are two cargos.
In the first cargo, there are two containers.
The first container contains two boxes, plus some other items.
The second container contains no boxes, but two items.
In the second cargo, there is one container with 3 items.
It follows the rules. Therefore, the container loader has worked correctly.
Explanation for sample 2:
The unbalanced brackets shows that the container loader has not worked correctly.
import sys
exp=input()
flag=0
for i in range(0,len(exp),1):
if(exp[i]=="{"):
flag+=1
if(exp[i]=="}"):
flag-=1
if(flag>1 or flag<=-1):
print("Invalid")
sys.exit()
flag=0
con=0
box=0
for i in range(0,len(exp),1):
if(exp[i]=='{'):
flag+=1
if (exp[i] == "}"):
flag -= 1
if (exp[i] == '('):
box += 1
if (exp[i] == ")"):
box -= 1
if(exp[i]=='['):
con+=1
if(exp[i]==']'):
con-=1
if(con>flag):
print("Invalid")
sys.exit()
if(con>flag or box<=-1): #box>con box>flag or
print("Invalid")
sys.exit()
flag=0
con=0
box=0
for i in range(0,len(exp),1):
if(exp[i]=="["):
con+=1
if(exp[i]=="]"):
con-=1
if(con>1):
print("Invalid")
sys.exit()
if(exp[i]=="("):
box+=1
if(exp[i]==")"):
box-=1
if(con>1 or con<=-1 or box<=-1): #or box>con
print("Invalid")
sys.exit()
#({})
flag=0
box=0
for i in range(0,len(exp),1):
if(exp[i]=="{"):
flag+=1
if(exp[i]=="}"):
flag-=1
if(exp[i]=="("):
box+=1
if(exp[i]==")"):
box-=1
if(box>flag):
print("Invalid")
sys.exit()
print("Valid")
The Weight Detection SensorThe Gocargo carriers has planned to automate the filling of cargos in the container. They have installed a weight detection sensor in the conveyor belt where cargos will be taken to the container. The sensor needs to be programmed in a way that it stops the conveyor sending the cargos, when the maximum capacity of the container is reached or exceeded.Please write a code to enable the sensor to automate this task of finding the number of...
The Cargo arrangementThe Gocargo carriers have a pattern of arranging the cargos in the container. Given the length of edge of the container, print the cargo arrangement pattern in the container as shown in the sample IO. The base of the container is always a square.Note: The Cargo are of unit length.Input format : The input is an integer that corresponds to the side length of the container.Output Format: Output is the cargo arrangement pattern inside the container.Please refer to the sample...
Palindromic CargoThe Gocargo carriers are celebrating their digitization process, which has given them a lot of benefits and ease of work for their employees. In account of this initiative they are offering their customers to ship their cargoes free of cost, if and only if the cargo names are palindromic.Given a cargo name, check whether the cargo name is a palindrome or not. Consider only alphabets while checking, remove special characters and spaces.Note : Define a function named check Palindrome()...
USING C LANGUAGE
Write a program that computes the total weight of a cargo. Ask the user to enter multiple inputs. For each input, the user indicate the weight and quantity of the boxes. The program computes and prints the total cargo weight The output should match the sample below. Make sure you print the input number (Input #1, Input #2,) 3 - Input # 1. Weight of the box (lbs): 4 Enter quantity: 2 Input #2. Weight of the...
in c++ please
RFIDs and lot Internet of things lloT) is one of the hottest technologies at the moment. The concept of loT is to provide objects with unique identifiers (UIDs) and the ability to transfer their date over a network without requiring human interaction. Radio frequency identification system (RFID) is a technology that aids computers to identify objects and record their metadata By connecting RFID readers to the Internet, it will be able to send objects' date over the...
Project description: Your group has been approached by YESD Department to pack and move the offices of six YESD faculty/staff currently located in 3rd floor (Brand Hall) to the 4th floor (Brand Hall). Details of the project are as follows: Items include books, computers, printers and other miscellaneous items. Note that furniture i.e. desks, cabinets, bookshelves etc. do not have to be moved. Exact number of boxes of material to be packed/moved is ten per office. Number of boxes available...
CODING IN PYTHON: Assume a customer is at a store purchasing exactly 4 items. The cashier inputs the items and their prices into the computer. Someone has provided the cashier a Python program that does the following: 1. Asks cashier for name of each item (use short names like nails, paint, etc.) 2. Asks cashier for price of each item A) Assume items are between $5 & $20. Have 1 item that is less than $10 3. Prints receipt header...
one mole of an ideal gas is in a closed container. Rank the
following parameters by the resulting pressure of the gas, from
lowest to highest
PHYSICS h 14) KQuestion 4 (of 17) value 10.00 points 1 out of 3 attemp Starting with the left-most column, populate the boxes from left to right without skipping empty boxes. Ties should be grouped in the same box. One mole of an ideal gas is in a closed container. Rank the following parameters...
1/ An element that has its display set to flex (its children become flex items). item container display container set container flex container 2/ When flex-basis is a value other than zero, extra space is divided up based on their flex ratios. An item with a flex ratio of 2 would get twice as much extra space allotted to it than an item with a flex ratio of 1 (although it may not end up twice as wide as 1...
Question 6: Representation in FOL...... Consider a world with balls and boxes, and the following relations: 15 points ball(r): x is a ball. • box (x): a is a box. • color(x, y): has color y. in(x, y): x is in y. Represent the following statements in first-order logic: 1. (2 pts) Some balls are not in any box. 2. (2 pts) Every box has some balls in it. 3. (2 pts) A ball cannot have more than one color....