add solutions for hw5
This commit is contained in:
@@ -18,17 +18,28 @@ public class FastScanner {
|
|||||||
|
|
||||||
boolean hasNextInt() {
|
boolean hasNextInt() {
|
||||||
if (line == null) return false;
|
if (line == null) return false;
|
||||||
while (pos < line.length() && Character.isWhitespace(line.charAt(pos))) pos++;
|
while (pos < line.length() && (Character.isWhitespace(line.charAt(pos)) ||
|
||||||
return pos < line.length();
|
Character.getType(line.charAt(pos)) == Character.START_PUNCTUATION ||
|
||||||
|
Character.getType(line.charAt(pos)) == Character.END_PUNCTUATION)) {
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
return pos < line.length() && (Character.isDigit(line.charAt(pos)) || line.charAt(pos) == '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
int nextInt() {
|
int nextInt() {
|
||||||
while (pos < line.length() && Character.isWhitespace(line.charAt(pos))) pos++;
|
while (pos < line.length() && (Character.isWhitespace(line.charAt(pos)) ||
|
||||||
|
Character.getType(line.charAt(pos)) == Character.START_PUNCTUATION ||
|
||||||
|
Character.getType(line.charAt(pos)) == Character.END_PUNCTUATION)) {
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
|
||||||
int start = pos;
|
int start = pos;
|
||||||
boolean negative = line.charAt(pos) == '-';
|
boolean negative = line.charAt(pos) == '-';
|
||||||
if (negative) pos++;
|
if (negative) pos++;
|
||||||
|
|
||||||
while (pos < line.length() && Character.isDigit(line.charAt(pos))) pos++;
|
while (pos < line.length() && Character.isDigit(line.charAt(pos))) {
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (int i = negative ? start + 1 : start; i < pos; i++) {
|
for (int i = negative ? start + 1 : start; i < pos; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user