×

EASY

# EXPLANATION

This is the easiest problem in the set. This problem can be solved various methods. For instance, if A - B mod 10 = 9, print A - B - 1, otherwise print A - B + 1. Be careful not to print 0 if A - B = 1. Your answer must be a positive integer.

# SETTER'S SOLUTION

Can be found here.

# TESTER'S SOLUTION

Can be found here.

This question is marked "community wiki".

19.8k350498541
accept rate: 35%

I'm not getting why my code is wrong.

# include<iostream>

using namespace std; int length(int n) {int r,c=0; while(n>0) { r=n%10; c++; n=n/10;
} return c; } int main() {
int a,b,n,s[10001],r,i,j,num; cin>>a; cin>>b; num=a-b; n=num; i=0; if(n!=0) { while(n>0) { r=n%10; s[i]=r; n=n/10; i++; } while(1) { srand( (unsigned)time(NULL) ); j=(rand()%10)-1; if(s[0]!=j) s[0]=j; break; } for(i=(length(num)-1);i>=0;i--) cout<<s[i]; } else cout<<1; system("PAUSE"); return 0; }

1
accept rate: 0%

# include<conio.h>

using namespace std;

int main(){ int num; int r;

int a; int b;

    cin >> a;
cin >> b;

r = (a - b)%10;

if(r <= 9 && r >= 1 ) {

if(a - b - 1 == 0) {
cout << "3" << endl;
return 0;
}
cout << a - b - 1 << endl;
}
else cout << (a - b) + 1 << endl;

getch();
return 0;


}

211
accept rate: 0%

 0 Why this code does not work?? class CielAB { public static void main(String args[]) { Scanner inp=new Scanner(System.in); String a=inp.nextLine(); String b[]=a.split(" "); int a1=new Integer(b[0]); int b1=new Integer(b[1]); int c1=a1-b1; if(c1%10==0) c1=c1+1; else c1=c1-1; System.out.println(c1); } } answered 18 Dec '15, 13:50 1 accept rate: 0%
 0 The compiler really doesn't take any other answer other than what is mentioned above. Same problem can be solved as if ((A-B)%10 ==0) Output (A-B+1) else Output (A-B-1) Please correct me if i am wrong. answered 11 Feb '16, 11:37 1 accept rate: 0% the question is absolutely correct. In your approach when a-b is 1 it will print 0 as answer and in constraints it is clearly written that answer should be a positive number. (16 May '18, 16:38)

# include <iostream>

using namespace std;

int main() { int x,y,dif,flag=0,count1=0,count2=0,ans,d[5],an[5]; cout<<"enter the A and B:"; cin>>x>>y;

if(x>y && x>0 && y>0 && x<10000 && y<10000)
{
dif=x-y;
int p=dif,q;
while(p!=0)
{
p /=10;
++count1;
}

cin>>ans;
q=ans;
while(q!=0)
{

q/=10;
++count2;
}
if(count1==count2)
{
for(int i=0;i<count1;i++)
{
d[i]=dif%10;
dif=(dif-d[i])/10;
an[i]=ans%10;
ans=(ans-an[i])/10;

}
for(int i=0;i<count1;i++)
{

if(d[i]!=an[i])
flag++;

}
if(flag==1)
else
cout<<"\n more than one digit error";

}
else{
cout<<"\n no. of digit are difference";
}


} else{ cout<<"\n No are too large or too small"; }

return 0;


}

hi a am new on codechef and i solved the problem mentioned above in codeblock but it is not submitting here.

1
accept rate: 0%

 0 I have a question regarding the formula what does A-B mod 10 = 9 do? I'm a newbie here answered 08 Aug '16, 22:07 1 accept rate: 0%

# include <stdio.h>

int main() { int t; scanf("%d",&t); while(t--) { int a,b,c,ans; scanf("%d %d",&a,&b); ans=fabs(a-b); if((ans%10)==9) ans=ans-1; else ans=ans+1; printf("%d\n",ans);} return 0; }

1
accept rate: 0%

 0 For java,with what name to save the program answered 13 Sep '16, 19:23 0★yash990 1 accept rate: 0%
 0 Following is my code in C#, but it says that answer is Wrong. I don't understand why. Please Help. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CodeChef_CEILAB { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string[] s1 = s.Split(' '); int A = int.Parse(s1[0]); int B = int.Parse(s1[1]); //Console.WriteLine("Enter First Number"); //int A = int.Parse(Console.ReadLine()); //Console.WriteLine("Enter Second Number"); //int B = int.Parse(Console.ReadLine()); var result = A - B; // First of all get the number of digits in result var ResCnt = digitCounter(result); var answer = result + 1; var AnsCnt = digitCounter(answer); if (ResCnt == AnsCnt) Console.WriteLine(answer); else Console.WriteLine(answer - 1); } static int digitCounter(int result) { var temp = result; int count = 1; while ((temp / 10) > 0) { count++; temp = temp / 10; } return count; } }  } Please let me know why the above code is wrong. Thanks in advance!! answered 24 Oct '16, 23:36 1●1 accept rate: 0%
 0 import java.io.; import java.util.Scanner; import java.lang.Math; class Ceil { public static void main (String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter two numbers: "); int a = sc.nextInt(); int b = sc.nextInt(); int difference = a-b; int temp = difference; int randomnumber = (difference%10); while(randomnumber==(difference%10)) randomnumber = (int)((Math.random()10)); int wrongnumber = 0; //Changing only the last digit wrongnumber = (((a-b)/10)*10)+randomnumber; System.out.println(wrongnumber); } } PS: Why is it not working? answered 09 Jan '17, 12:05 1 accept rate: 0%
 0 Instead of changing first digit , i am changing last digit of resultant answer. It is giving me Wrong Answer . Can you tell why? import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; /* Class for buffered reading int and double values / class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader(new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt( next() ); } static double nextDouble() throws IOException { return Double.parseDouble( next() ); }  } class CIELAB { public static void main ( String[] args ) throws IOException { Reader.init(System.in); int a = Reader.nextInt(); int b = Reader.nextInt();  int res = a - b; int bb = res; boolean flag = false; while ( true ) { int rem = bb%10; bb = bb/10; if ( bb >= 0 && bb <= 9 ) { if ( rem == 9 ) { flag = true; } break; } } if ( flag == true ) { System.out.println(res-1); } else { System.out.println(res+1); } }  } Thanks in advance (Y) answered 01 Jun '17, 00:45 2★askwhat 1 accept rate: 0%
 0 You have a nice post please do share such post answered 01 Jun '17, 10:55 -5 accept rate: 0%
 0 Thanks sharing this question answered 01 Jun '17, 10:57 -5 accept rate: 0%
 0 It is very nice answered 01 Jun '17, 10:59 -5 accept rate: 0%
 0 Weird problem. I got an AC after some WA, I changed the approach but I have no idea what was wrong with the first approach. Maybe something's wrong with how it tests solutions. answered 13 Jul '17, 22:06 0★azazello 3●2 accept rate: 0%
 0 What is wrong here??????? import java.util.; public class Main { public static void main(String []args) { Scanner sc=new Scanner(System.in); int a,b,x,d; a=sc.nextInt(); b=sc.nextInt(); x=a-b; d=x%10; x=x/10; d=(d+1)%10; x=x10+d; System.out.println(x); } } answered 25 Jul '17, 14:30 2★synyst3r 1 accept rate: 0%

# include<stdio.h>

int main() { int a,b,ans,result; scanf("%d",&a); scanf("%d",&b); result=a-b; if(result%10==0) ans=result+1; else ans=result-1; printf("%d",ans); } why this is wrong?

0★pb2108
1
accept rate: 0%

 0 #include using namespace std; int main() { int a,b; cin>>a>>b; a-=b; string s=""; s+=to_string(a); if(s[0]=='1') s[0]='9'; else s[0]='1'; cout<
 0 Instead of changing the last digit, I tried to change the first one. This solution is giving me a wrong answer. Can someone please help me out? int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long a,b; cin >> a >> b; long long ans = a-b; if(!ans) cout << 1 << "\n"; else{ long long temp = ans; long long c = -1; while(temp>0){ temp /= 10; c++; } if(c==0){ if(ans == 1) cout << 2 << "\n"; else cout << 1 << "\n"; } else{ if(ans/pow(10,c) == 9) cout << ans - pow(10,c) << "\n"; else cout << ans + pow(10,c) << "\n"; } } return 0; }  answered 16 Mar '18, 18:54 1 accept rate: 0%

# include<conio.h>

void main() { int a,b; printf("enter the value of a and b:"); scanf("%d%d",&a,&b); if((a-b)%10==9) if(a-b==1) break; printf(\n a-b-1); else printf(\n a-b+1); getch(); }

This answer is marked "community wiki".

1
accept rate: 0%

/ I don't understand what is wrong with this code? /

# include<stdio.h>

int main() { int a,b; scanf("%d %d",&a,&b); int temp = a-b; temp = temp/10; int result = 0; int power = 10; int k; while(temp) { k = temp%10; result = result + kpower; temp = temp/10; power = power10; } printf("%d\n",result); return 0; }

1
accept rate: 0%

(01 Jun '18, 00:46)
 0 For example consider the two numbers to be 1020 and 20 the difference will give you 1000 printing 1000 will be wrong printing less than 1000 is wrong (no of digits is getting reduced) 0100 0010 0001 are wrong answers, because they have 0 infront of them. So, what should be the answer in this case ? answered 04 Jan, 09:28 1 accept rate: 0%

# python script, one liner:

a,b=(int(x) for x in input().split(' '));print(a-b+1 if (a-b)%10<9 else a-b-1)

1
accept rate: 0%

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,719
×3,770
×10
×6

question asked: 22 Nov '12, 16:23

question was seen: 12,863 times

last updated: 20 Feb, 04:34