Solution of 'Three Friends' (Codeforces)
Hello everyone! Here's my solution of the question-'Three Friends' from Codeforces. Any suggestion for me is highly appreciated. Happy Coding!
question link: https://codeforces.com/problemset/problem/1272/A
#include <bits/stdc++.h>
#define long long long int
using namespace std;
int main()
{
int q;
cin>>q;
int d[q];
for(int m=0;m<q;m++){
int a,b,c,min=1999999999;
cin>>a>>b>>c;
int a1[3]={a+1,a,a-1};
int b1[3]={b+1,b,b-1};
int c1[3]={c+1,c,c-1};
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
int s=abs(a1[i]-b1[j])+abs(b1[j]-c1[k])+abs(c1[k]-a1[i]);
if(min>s) {min=s;}
}
}
}
d[m]=min;
}
for(int i=0;i<q;i++) cout<<d[i]<<'\n';
}
Comments
Post a Comment