[Solution] Too many Floors solution codechef

Too many Floors solution codechef – Chef and Chefina are residing in a hotel.

There are 1010 floors in the hotel and each floor consists of 1010 rooms.

  • Floor 11 consists of room numbers 11 to 1010.
  • Floor 22 consists of room numbers 1111 to 2020.
  • Floor ii consists of room numbers 10(i1)+110⋅(i−1)+1 to 10i10⋅i.

Table of Contents

[Solution] Too many Floors solution codechef

You know that Chef’s room number is XX while Chefina’s Room number is YY.
If Chef starts from his room, find the number of floors he needs to travel to reach Chefina’s room.

Input Format

  • First line will contain TT, number of test cases. Then the test cases follow.
  • Each test case contains of a single line of input, two integers X,YX,Y, the room numbers of Chef and Chefina respectively.

Output Format

For each test case, output the number of floors Chef needs to travel to reach Chefina’s room.

[Solution] Too many Floors solution codechef

  • 1T10001≤T≤1000
  • 1X,Y1001≤X,Y≤100
  • XYX≠Y

Sample Input 1 

4
1 100
42 50
53 30
81 80

Sample Output 1 

9
0
3
1

[Solution] Too many Floors solution codechef

Test Case 11: Since Room 11 is on 1st1st floor and Room 100100 is on 10th10th floor, Chef needs to climb 99 floors to reach Chefina’s Room.

Test Case 22: Since Room 4242 is on 5th5th floor and Room 5050 is also on 5th5th floor, Chef does not need to climb any floor.

Test Case 33: Since Room 5353 is on 6th6th floor and Room 3030 is on 3rd3rd floor, Chef needs to go down 33 floors to reach Chefina’s Room.

Test Case 44: Since Room 8181 is on 9th9th floor and Room 8080 is on 8th8th floor, Chef needs to go down 11 floors to reach Chefina’s Room.

For Solution

Click Here

Leave a Comment