update
This commit is contained in:
45
java/sum/SumLongOctal.java
Normal file
45
java/sum/SumLongOctal.java
Normal file
@@ -0,0 +1,45 @@
|
||||
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;
|
||||
}
|
||||
|
||||
int numLength = num.length();
|
||||
|
||||
if (
|
||||
num.charAt(numLength - 1) == 'o' || num.charAt(numLength - 1) == 'O'
|
||||
) {
|
||||
return new BigInteger(
|
||||
num.substring(0, num.length() - 1),
|
||||
8
|
||||
).longValue();
|
||||
} else {
|
||||
return Long.parseLong(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user