ciel A-b problem

Question=[1]: http://www.codechef.com/problems/CIELAB/
My solution=[1]:http://www.codechef.com/viewsolution/6605858
Error type=wrong answer
PLz fix the code for me

@coder_baba here is your corrected code… just change if(r%10==0) to if(r%10!=9) and you will get AC. You have to check for the digit 9 because if the result has 9 in its units place and you increment the result then the final result will contains one extra digit than the required answer(Read in the problem statement - it says digits should be same as in A and B).

import java.io.*;

class ceil
{
	public static void main(String args[])throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int X;
		int Y;
		String[] ar = br.readLine().split(" ");
		X = Integer.parseInt(ar[0]);
		Y = Integer.parseInt(ar[1]);
		int r;
		r = X - Y;
		if ( r%10!=9 )
			r++;
		else r--;
		System.out.println(r);
	}
}

here is your accepted code.

I have understood your logic,but still can’t figure out why my code is wrong can you provide me any such test case so that I can understand my mistake.Same number of digits is also maintained in my code.

replace your condition if(r%10==0) with if(r%10==0 || r==1) because when difference is 1 then your code will output 0.but the output should we greater than 1 according to constraints.so the corrected code is.import java.io.*; class ceil { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int X;int Y; String[] ar = br.readLine().split(" "); X=Integer.parseInt(ar[0]); Y=Integer.parseInt(ar[1]); int r; r=X-Y; if(r%10==0||r==1) r++; else r--; System.out.println(r); } }

Can you tell me why my solution is not working? https://www.codechef.com/viewsolution/9973351

#include

using namespace std;

int main()
{
int a,b,c;
cout<<“Enter the value of a=”<<endl;
cin>>a;
cout<<“Enter the value of b=”<<endl;
cin>>b;
if(1<b<a<10000)
{
c=a-b;
if(c%10==0)
c+=1;
else
c-=1;
cout<<c;
}
else
cout<<“Wrong Input”;

return 0;

}
//CAN YOU TELL ME WHY MY CODE IS NOT ACCEPTED???

Check that if a % b == 9 print a-b+1…Else print a-b+1

@amazingrainbow

This may be due to your incorrect printing format.

import java.io.*;

class ceil
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int X;
int Y;
String[] ar = br.readLine().split(" ");
X = Integer.parseInt(ar[0]);
Y = Integer.parseInt(ar[1]);
int r;
r = X - Y;
if ( r%10!=9 )
r++;
else r–;
System.out.println®;
}
}

Where am I wrong?
I replaced the last bit by XOR

#include <bits/stdc++.h>

using namespace std;

int main() {

int a, b;
cin >> a >> b;
int res = a-b;

cout << res <<endl;
res ^= (1<<0);
cout << res <<endl;

return 0;

}