Problem Link - Link
Author - Rishabh Verma
Tester - Hemant Singh
Editorialist - Rishabh Verma
Difficulty :- Easy
Problem -
You have given three point on number line x,a,b . You have to tell which point a or b is nearest to x . Note if both point are at same distance consider a as nearest .
Explanation -
Calculate absolute difference of x,a and x,b by the formula abs(x-a) & abs(x-b) respectively and now compare and output the answer .
My Solution -
#include <bits/stdc++.h>
using namespace std;
int main() {
int t; cin>>t;
while(t-->0){
int x,a,b;
cin >> x >> a >> b;
a = abs(x - a);
b = abs(x - b);
if(a <= b) cout << "A" << endl;
else cout << "B" << endl;
}
return 0;
}