// http://www.codeeval.com/open_challenges/45/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
class Main {
public static void main(String[] args) {
reverse_add.main(args);
}
}
class reverse_add {
public static void main(String[] args) {
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
if (LOCAL_TEST)
CodeEvalGetInput("e:\\zin.txt");
else
CodeEvalGetInput(args[0]);
}
public static void CodeEvalGetInput(String arg) {
try {
File file = new File(arg);
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
while ((line = in.readLine()) != null) {
String[] lineArray = line.split("\\s");
if (lineArray.length > 0) {
// Process line of input Here
Process(lineArray);
}
}
} catch (IOException e) {
System.out.println("File Read Error: " + e.getMessage());
}
}
private static void Process(String[] lineArray) {
long N = Long.valueOf(lineArray[0]);
int it = 0;
String sum = "";
while (true) {
it++;
long rev = Long.valueOf(new StringBuffer(String.valueOf(N)).reverse()
.toString());
sum = String.valueOf(N + rev);
if (sum.equals(new StringBuffer(sum).reverse().toString())) {
break;
}
N = N + rev;
}
System.out.println(it + " " + sum);
}
}
No comments:
Post a Comment