Volume Control: VOLCONTROL

Volume Control CodeChef Solution in C, C++, Java, and Python 3

Public Submission link: Click here (anyone can submit here )

CU Submission link: Click here (need login by CU account)


Chef is watching TV. The current volume of the TV is XX. Pressing the volume up button of the TV remote increases the volume by 11 while pressing the volume down button decreases the volume by 11. Chef wants to change the volume from XX to YY. Find the minimum number of button presses required to do so.

Input Format

  • The first line contains a single integer TT – the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains two integers XX and YY – 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 XX to YY.

Constraints

  • 1≤T≤100
  • 1≤X,Y≤100

Sample Input 1

2
50 54
12 10

Sample Output 1

4
2

Volume Control CodeChef Solution in C

int T;
	scanf("%d",&T);
	while(T--)
	{
	    int x,y;
	    scanf("%d%d",&x,&y);
	    if(x < y)
	    {

	        printf("%d\n",y-x);
	    }
	    else
	    {
	        printf("%d\n",x-y);
	    }
	}
	return 0;
}

Volume Control CodeChef Solution in C++ 17

// your code goes here
	int t;
	cin>>t;
	for(int i=0; i < t; i++){
	    int x, y;
	    cin>>x>>y;
	    if((x>y) || (x==y)){
	        cout << (x-y) << endl;
	    }
	    else{
	        cout << (y-x) << endl;
	    }

	}
	return 0;
}

Volume Control CodeChef Solution in Python 3

t = int(input())
for i in range(t):
    l=list(map(int,input().split()))
    ans = {True:"YES", False:"NO"}
    print(max(l)-min(l))

Volume Control CodeChef Solution in Java

/* 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
	{
	    Scanner sc=new Scanner(System.in);
	    int t=sc.nextInt();
	    for( int i=0;i< t;i++)
	    {
	        int a=sc.nextInt();
	        int b=sc.nextInt();
	        if(b>=a)
	        {
	            System.out.println(b-a);

	        }
	        else if(b < a)
	        {
	            System.out.println(a-b);
	        }
	    }
	}
}

More Codechef Solution: Click Here




Volume Control CodeChef Solution from

Volume Control CodeChef Solution
The content uploaded on this website is for reference purposes only. Please do it yourself first.
Home
Account
Cart
Search