Who is smarter
Rahul and Rama are siblings. Rahul believes that he is smarter than Rama so Rama decides to teach him a lesson. She gives him 2 non-negative integers A and B and asks him to reverse the two numbers and tell the greater one.
If the numbers after reversing contain leading zeros, you have to ignore them. See the sample examples for better clarification.
Input Format
The only line containing 2 non-negative integers A and B.
Constraints
0 <= A, B <= 1000, 000, 000
Output Format
Print the answer to the problem.
Sample TestCase 1
Input
12 100
Output
21
Explanation
The numbers after reversing becomes 21 (12) and 1 (001). Clearly, 21 is bigger.
Sample TestCase 2
Input
100 100
1
Output
Explanation
Both of the numbers after reversing become 1. So, 1 is the answer.
Java Solution
import java.io.*;
import java.util.*;
public class CandidateCode {
public static void main(String args[] ) throws Exception {
//Write code here
Scanner sc=new Scanner(System.in);
int num1=sc.nextInt();
int num2=sc.nextInt();
int reverse1 = 0;
int lastDigit1 = 0;
while (num1 >= 1) {
lastDigit1 = num1 % 10;
reverse1 = reverse1 * 10 + lastDigit1;
num1 = num1 / 10;
}
int reverse2 = 0;
int lastDigit2 = 0;
while (num2 >= 1) {
lastDigit2 = num2 % 10;
reverse2 = reverse2 * 10 + lastDigit2;
num2 = num2 / 10;
}
if(reverse1 > reverse2)
System.out.println(reverse1);
else
System.out.println(reverse2);
}
}
1 Comments
same question but i need c# program
ReplyDelete