Skip to content

Commit

Permalink
Solution to Three Friends
Browse files Browse the repository at this point in the history
  • Loading branch information
ritwiksingh21 authored Oct 8, 2020
1 parent 2bd511a commit 8edd4c4
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Three Friends/Solution Three Friends in C
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
int cal(int a,int b,int c){
return abs(a - b) + abs(a - c) + abs(b - c);
}
int min(int a, int b){
int mini;
if(a == b){return a;}
else{
mini = a<b?a:b;
return mini;
}
}
int main()
{
int i,j,k,na,nb,nc,a,b,c,ans,t;
scanf("%d", &t);
while(t--){
scanf("%d %d %d", &a, &b, &c);
ans=cal(a,b,c);
for(i=-1;i<=1;i++){
for(j=-1;j<=1;j++){
for(k=-1;k<=1;k++){
na = a + i;
nb = b + j;
nc = c + k;
ans = min(ans, cal(na, nb, nc));
}
}
}
printf("%d\n", ans);
}
return 0;
}

0 comments on commit 8edd4c4

Please sign in to comment.