update
This commit is contained in:
42
java/sum/SumHex.java
Normal file
42
java/sum/SumHex.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package sum;
|
||||
|
||||
/**
|
||||
* @author Nikita Doschennikov (me@fymio.us)
|
||||
*/
|
||||
public class SumHex {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int 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 int compute(String num) {
|
||||
int res = 0;
|
||||
if (num.isEmpty()) {
|
||||
res += 0;
|
||||
} else if (
|
||||
num.length() >= 2 &&
|
||||
num.charAt(0) == '0' &&
|
||||
(num.charAt(1) == 'x' || num.charAt(1) == 'X')
|
||||
) {
|
||||
res += Long.decode(num);
|
||||
} else {
|
||||
res += Integer.parseInt(num);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user