Social Icons

twitterfacebookgoogle pluslinkedinrss feedemail

Monday, August 27, 2012

BUBTPC 2nd Problem C - Distance & Displacement


Distance & Displacement
Problem Statement:
There are two interesting things in physics, they are:
Distance: Distance is the total length covered by a moving object irrespective of the direction of motion. Here only magnitude is needed.
Displacement: Displacement is distance measured in a straight line and in a specified direction. So both magnitude and direction are important. For example:
A car travels 5 km to east and makes a U-turn back to travel a further distance of 3 km. Then:


I.  Distance Covered: 5 + 3 = 8 km    II. Displacement: 5 - 3 = 2 km
As a programmer write a program that will be used to find distance & displacement of a given entity.

Input:
The first line of input will contain a number N (1<=N<=100), which will denote the number of sample we want to take. The second line contains distance and sign of distance for N times.

Output:
In output there will be two lines. The first line contains total distance covered by the object and the second line contains the displacement of the object.

Sample Input/Output:

Sample input
Sample output
3
X=? 12
Sign=? +
X=? 10
Sign=? +
X=? 5
Sign=? -
DISTANCE: 27
DISPLACEMENT: 17


Problem setter: Md. Saifur Rahman, Asst. Professor, Dept. of CSE
Bangladesh University of Business and Technology (BUBT)

No comments:

Post a Comment

 

Sample text

Sample Text