Debugging on Codechef

How can debug my code on CodeChef
Problem: CIELAB Problem - CodeChef
this is my code :
#include<bits/stdc++.h>
using namespace std;

int main()
{
int a,b;
scanf(“%d %d”,&a,&b);
int sub=a-b;
int lastDigit=sub%10;
if(lastDigit==0) sub++;
else sub-=lastDigit;
printf(“%d”,sub);
printf(“\n”);
return 0;
}

Debugging skills develop over time and with practice
This is how i debug my code

  • think of corner cases
  • print debug statements
  • generate test cases
  • compare output of random test cases with brute force approach
  • clean the code, give logical names to variables (something which most people dont do in CP)
  • explain the logic to someone or yourself again

Coming to your code, it fails condition that the answer should have leading zeroes in some special test cases
can you guess that test case??
think and if in case you are unable to do it then look the link below
i have added two lines to correct ur soln
https://www.codechef.com/viewsolution/24093684
however it can be optimized further as
https://www.codechef.com/viewsolution/24093674