Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VolumeControlproblem.cpp #681

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions VolumeControlproblem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*Problem
Chef is watching TV. The current volume of the TV isX. 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.

Input Format
The first line contains a single integer T - the number of test cases. Then the test cases follow.
The first and only line of each test case contains two integers X and Y - 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 X to Y.

CODE-*/
#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
int x,y;
while(t--){
cin>>x>>y;
if(x>=y){
cout<<(x-y)<<endl;
}
else{
cout<<(y-x)<<endl;
}
}
return 0;
}