forked from builder-of-web3/HackR_Java_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse.java
More file actions
58 lines (53 loc) · 1.53 KB
/
reverse.java
File metadata and controls
58 lines (53 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class TestClass {
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int N = Integer.parseInt(line);
ArrayList<String> arint = new ArrayList<String>();
for (int i = 0; i < N; i++) {
arint.add(br.readLine());
}
for(int i = 0; i < N; i++){
System.out.println(result(arint.get(i)));
}
}
public static int result(String str) {
//System.out.println(str);
String[] splitStr = str.split("\\s+");
//System.out.println("string"+splitStr[0]);
String h1 = splitStr[0];
int one = rev(h1);
//System.out.println(one);
String h2 = splitStr[1];
int two = rev(h2);
//System.out.println(two);
int sum=0;
sum = rev(one + two+"");
//System.out.println(sum);
return sum;
}
public static int rev(String example){
char[] chars = example.replaceAll("^0+", "").toCharArray();
List<Integer> list = new ArrayList<Integer>();
for (char c: chars) {
try {
list.add(Integer.parseInt(Character.toString(c)));
}
catch (NumberFormatException nfe) {
}
}
Collections.reverse(list);
//System.out.println(list);
String l1="";
for(int i=0;i<list.size();i++ ){
l1 = l1 + list.get(i);
}
//System.out.println("l1"+l1);
return Integer.parseInt(l1);
}
}