Skip to main content

Posts

Showing posts from September, 2017

INFIX TO POSTFIX

Infix expression: The expression of the form a op b. When an operator is in-between every pair of operands. Postfix expression: The expression of the form a b op. When an operator is followed for every pair of operands. Examples of Infix to Postfix Let’s consider few examples to elaborate the  infix  and  postfix  forms of expressions based on their precedence order: Infix Postfix A + B 12 + 60 – 23 (A + B)*(C – D ) A ­ B * C – D + E/F A B + 12 60 + 23 – A B + C D – * A B ­ C*D – E F/+ A programmer can write the operators either after the operands i.e. postfix notation or before the operands i.e. prefix notation. Some of the examples are as under: Infix Postfix A + B A B + 12 + 60 – 23 12 60 + 23 – (A + B)*(C – D ) A B + C D – * A ­ B * C – D + E/F A B ­ C*D – E F/+ STEPS:- • We use a stack  • When an operand is read, output it  • When an operator is read         – Pop until the top of the st...

Truck Tour

Truck Tour Suppose there is a circle. There are   petrol pumps on that circle. Petrol pumps are numbered   to   (both inclusive). You have two pieces of information corresponding to each of the petrol pump: (1) the amount of petrol that particular petrol pump will give, and (2) the distance from that petrol pump to the next petrol pump. Initially, you have a tank of infinite capacity carrying no petrol. You can start the tour at any of the petrol pumps. Calculate the first point from where the truck will be able to complete the circle. Consider that the truck will stop at each of the petrol pumps. The truck will move one kilometer for each litre of the petrol. Input Format The first line will contain the value of  . The next   lines will contain a pair of integers each, i.e. the amount of petrol that petrol pump will give and the distance between that petrol pump and the next petrol pump. Constraints: Ou...

EQUAL STACK

You have three stacks of cylinders where each cylinder has the same diameter, but they may vary in height. You can change the height of a stack by removing and discarding its topmost cylinder any number of times. Find the maximum possible height of the stacks such that all of the stacks are exactly the same height. This means you must remove zero or more cylinders from the top of zero or more of the three stacks until they're all the same height, then print the height. The removals must be performed in such a way as to maximize the height. Note:  An empty stack is still a stack. Input Format The first line contains three space-separated integers,  ,  , and  , describing the respective number of cylinders in stacks  ,  , and  . The subsequent lines describe the respective heights of each cylinder in a stack  from top to bottom : The second line contains   space-separated integers describing the cylinder heights i...