We have to make a pipeline (gas pipeline). We have some pieces of pipes that is on the same line we want the pipeline on. But they are scattered on the entire line and are different sizes-

Now we have to move all the pieces and solder to make one single piece- so that we can order a single piece for the remaining legth-

Now we want to do this with least movement of the pieces- The larger the piece the more the cost- Cost is same for long distance or long distance because the most costly operation is loading and unloading the pipe on the truck-

Input:

3 integers each line separated by comma-

piece number , length of the piece, the starting position

Output-

2 integers each line separated by comma-

piece number, move to position-

While moving you can not move a large piece in a small gap of two pieces-

Sample input:

1, 10, 5

2, 30, 30

3, 90, 5

4, 130, 20

Sample output:

1, 0

2, 5

4, 10

# Programming Fundamentals

## Tuesday, January 18, 2011

## Monday, September 13, 2010

### Anagrams

Find all anagrams from a dictionary.

Anagram of a word is another word that is just rearrange of the letters of first word-

pots, stop, tops are anagrams of each other.

Anagram of a word is another word that is just rearrange of the letters of first word-

pots, stop, tops are anagrams of each other.

### Rotation of a string

We have a string "ABCDEFGH". Write a program that rotates the string to make it "DEFGHABC". We have rotated the string by 3. You can not use any extra space except a few constant length primitive ones.

## Wednesday, September 1, 2010

### What is the base of a number

### Problem Description

We use letters (A-Z) and digits (0-9) to represent a number. For example A0 in hexadecimal number is equal to 160 in decimal number and 240 in octal number. Given 2 numbers which are equal in two different base and given base of one number you have to find out base of another number.### Input

Three words in each line separated by spaces: first word is first number and second word is base of first number in decimal and third word is a number that is equal to first number for some different base. Letters will be capital always.### Output

Print out the base of second number in decimal and zero if can not find any base that is 2-36.

### Sample input

A0 16 160160 10 240

### Sample Output

108

## Monday, August 30, 2010

### The first problem

### Problem Description

Write a program that takes two integer numbers and find the distance between them.### Input

Sequence of two numbers that fits in 4 byte integer in a computer in each line separated by whitespace character.

### Output

Distance between each pair in each line.

### Sample input

1 25 7

### Sample Output

12

Subscribe to:
Posts (Atom)