Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Chef is watching TV. The current volume of the TV is X. Pressing the volume up
button of the TV remote increases the volume by 1 while pressing the volume down
button decreases the volume by 1. Chef wants to change the volume from X to Y. Find the minimum number of button presses required to do so.
For each test case, output the minimum number of times Chef has to press a button to change the volume from X to Y.
Input: 2
50 54
12 10
Output: 4
2
Test Case 1: Chef can press the volume up
button 4 times to increase the volume from 50 to 54.
Test Case 2: Chef can press the volume down
button 2 times to decrease the volume from 12 to 10.
#include <iostream>
using namespace std;
int main() {
int i ;
cin >> i;
while(i>0){
int a ,b;
cin >> a >>b;
int min = a - b;
if(min < 0){
min = min*(-1);
}
cout << min << endl;
i--;
}
return 0;
}
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
int X=sc.nextInt();
int Y=sc.nextInt();
if(X>Y)
{
System.out.println(X-Y);
}
else
{
System.out.println(Y-X);
}
}
}
}
In our experience, we suggest you solve this Volume Control CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Volume Control CodeChef Solution
I hope this Volume Control CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>