fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int T;
  8. cin>>T;
  9. for(int i=0;i<T;i++)
  10. {
  11. cout<<endl;
  12. int A,B,C,rem,avg,count=0;
  13. cin>>A>>B>>C;
  14. rem=(A+C)%2;
  15. avg=(A+C)/2;
  16. if(rem==0)
  17. {
  18. if(B>avg)
  19. count=avg-B;
  20. else
  21. count=B-avg;
  22. }
  23. else if(rem==1 )
  24. {
  25. count++;
  26. //This was to convert rem=0
  27. if(B<avg)
  28. count+=avg-B;
  29. else
  30. count+=B-avg-1;
  31. }
  32. else if(rem==-1 )
  33. {
  34. count++;
  35. if(B<avg)
  36. count+=avg-B-1;
  37. else
  38. count+=B-avg;
  39. }
  40.  
  41. cout<<abs(count);
  42. }
  43. }
Success #stdin #stdout 0s 4388KB
stdin
Standard input is empty
stdout
Standard output is empty