42 lines
1.0 KiB
Java
42 lines
1.0 KiB
Java
package sum;
|
|
|
|
import java.math.BigInteger;
|
|
|
|
/**
|
|
* @author Nikita Doschennikov (me@fymio.us)
|
|
*/
|
|
public class SumLongOctal {
|
|
public static void main(String[] args) {
|
|
long res = 0;
|
|
for (String arg : args) {
|
|
StringBuilder builder = new StringBuilder();
|
|
for (char c : arg.toCharArray()) {
|
|
if (!Character.isWhitespace(c)) {
|
|
builder.append(c);
|
|
} else {
|
|
res += compute(builder.toString());
|
|
builder = new StringBuilder();
|
|
}
|
|
}
|
|
res += compute(builder.toString());
|
|
}
|
|
System.out.println(res);
|
|
}
|
|
|
|
static long compute(String num) {
|
|
if (num.isEmpty()) {
|
|
return 0L;
|
|
}
|
|
|
|
if (num.endsWith("o") || num.endsWith("O")) {
|
|
String oct = num.substring(0, num.length() - 1);
|
|
|
|
BigInteger bi = new BigInteger(oct, 8);
|
|
|
|
return bi.longValue();
|
|
} else {
|
|
return Long.parseLong(num);
|
|
}
|
|
}
|
|
}
|