$25
CMPUT 275 - Tangible Computing
Morning Problem: I Hate Stairs
Description
I hate stairs! At least ones you have to go up. Going down is ok.
Unfortunately all the elevators in my incredibly tall office building are broken. So I have to
take the stairs. Even worse, I have many meetings today on various floors.
I will tell you the floors of the meetings I must attend in the order they will occur. You tell
me the total number of floors I must ascend throughout my day.
More specifically, I will give you a sequence of integers indicating the floors my meetings are
held (in the order they are held). The first integer is the floor I am currently on (don’t worry
about how I got there). You should print the total number of floors I go up throughout the
day. Do not worry about counting the number of floors I go down.
Input
The input will consist of 2 lines. The first line consists of a single integer n indicates the
number of meetings I have. This is always between 1 and 1000. The second consists of n
space-separated integers between 1 and 106
indicating the floor of a meeting I must attend.
These will appear in the order I must attend them.
Output
Output a single line containing a single integer indicating the total number of floors I go up
throughout the day.
Sample Input
4
1 2 1 3
Sample Output
3
Explanation: I go up 1 floor when ascending from floor 1 to floor 2. I do not go up any
floors (in fact, I go down) when I go back down to floor 1. Then I go up 2 floors from floor
1 to floor 3. In total, I ascended 3 floors throughout the day.
Sample Input
4
2 1 1 2
Sample Output
1
Explanation: The only time I go up a floor is from the meeting at floor 1 to the meeting
at floor 2.
Sample Input
2
3 2
Sample Output
0
Explanation: Thankfully I never have to go up any floors!