Friday, May 3, 2019

Ciel and A-B

Problem Problem Description

 "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. Constraints 1 <= B < A<=10000"

 Test Case 1 Input (stdin)
 5858 1234

 Expected Output
 4625 

Test Case 2 Input (stdin)
 5858 3214

Expected Output
 2645

Solution

#include <stdio.h>

int main(void) {
int a,b,c;
scanf("%d%d",&a,&b);
c=a-b;
if(c%2==0||c==1)
printf("%d",c+1);
else
printf("%d",c-1);
return 0;
}

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...