DEV Community

Cover image for Ciel and A-B Problem
Gourav Kadu
Gourav Kadu

Posted on

2 1

Ciel and A-B Problem

In Ciel's restaurant, a waiter is training. Since the waiter isn't good at arithmetic, sometimes he gives guests wrong change. Ciel gives him a simple problem. What is A-B (A minus B) ?

Surprisingly, his answer is wrong. To be more precise, his answer has exactly one wrong digit. Can you imagine this? Can you make the same mistake in this problem?

Input

An input contains 2 integers A and B.

Output

Print a wrong answer of A-B. Your answer must be a positive integer containing the same number of digits as the correct answer, and exactly one digit must differ from the correct answer. Leading zeros are not allowed. If there are multiple answers satisfying the above conditions, anyone will do.

Sample input:

5858 1234
Enter fullscreen mode Exit fullscreen mode

Sample output

4625
Enter fullscreen mode Exit fullscreen mode

Output details:

The correct answer of 5858-1234 is 4624. So, for instance, 2624, 4324, 4623, 4604 and 4629 will be accepted, but 0624, 624, 5858, 4624 and 04624 will be rejected.

Solution:-

import java.util.*;

class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
    Scanner sc= new Scanner(System.in);
    int n= sc.nextInt();
    int m = sc.nextInt();
    int res = 0;
    if(n>m) {
        res= n-m;
    }else if(m>n) {
        res=m-n;
    }else {
        res=0;
    }
    int rem = res%10;


        if(rem<9) {
            System.out.println(res+1);
        }
        else if(rem == 9) {
            System.out.print(res-1);
        }


    sc.close();
    }
}
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up