Created
June 23, 2019 19:43
-
-
Save sumitsingh6/4eaa59c6f9bb3abb38a5e9643a3b98b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.BufferedReader; | |
| import java.io.InputStreamReader; | |
| import java.util.StringTokenizer; | |
| public class Addrev { | |
| public static void main(String[] args)throws Exception { | |
| BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); | |
| int count = Integer.parseInt(in.readLine()); | |
| Integer input[][] = new Integer[count][2]; | |
| for(int i = 0; i < count; i++) { | |
| StringTokenizer tk = new StringTokenizer(in.readLine()); | |
| input[i][0] = Integer.parseInt(tk.nextToken()); | |
| input[i][1] = Integer.parseInt(tk.nextToken()); | |
| } | |
| for(int i = 0; i < count; i++) { | |
| int sum = reverse(input[i][0]) + reverse(input[i][1]); | |
| System.out.println(reverse(sum)); | |
| } | |
| } | |
| static int reverse(int num) { | |
| int rev = 0; | |
| while(num != 0) { | |
| int digit = num % 10; | |
| rev = rev * 10 + digit; | |
| num /= 10; | |
| } | |
| return rev; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.spoj.com/problems/ADDREV/