Problem
Chef is watching TV. The current volume of the TV is . Pressing the volume up
button of the TV remote increases the volume by while pressing the volume down
button decreases the volume by . Chef wants to change the volume from to . Find the minimum number of button presses required to do so.
Input Format
- The first line contains a single integer - the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two integers and - the initial volume and final volume of the TV.
Output Format
For each test case, output the minimum number of times Chef has to press a button to change the volume from to .
Constraints
Sample 1:
2 50 54 12 10
4 2
Explanation:
Test Case 1: Chef can press the volume up
button times to increase the volume from to .
Test Case 2: Chef can press the volume down
button times to decrease the volume from to
Program :
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int t,x,y;
Scanner sc=new Scanner(System.in);
t=sc.nextInt();
while(t-->0)
{
int a=sc.nextInt();
int b=sc.nextInt();
System.out.println(Math.abs(a-b));
}
}
}
0 Comments