Contest Code:PRACTICE Problem Code:CIELAB


int main(){
int i,j,k;

k = i-j;
if(k%10!=9) k++; else k–;


return 0;
why we are using mod 10 !=9
can some one explain

it is for the case our value is not equal to 9, in that case we increment it by 1…otherwise we decrease by 1.

1 Like

that i understand but why we are applying that condition cannt we simply write
using namespace std;

int main() {
int a,b;
int c=(a-b)+1;

Think it in this way,

Let us suppose for our example, a = 875, b = 466

Thus, a - b = 875 - 466
= 409

Thus, a - b + 1 = 410

But, 2 digits are misplaced here, the tens digit should have been 0, and its 1. And the ones digit should have been 9 but it is 0.

Thus, you would get a WA. To avoid this conversion, the code have the statement:

if(k%10 !=9)

1 Like