add solutions for hw5
Some checks failed
Fast Reverse Tests / test (push) Has been cancelled
Reverse Tests / test (push) Successful in 11s
Sum Tests / test (push) Successful in 10s
Word Stat Tests / test (push) Successful in 9s

This commit is contained in:
2026-02-02 12:21:38 +05:00
parent 304f238a8a
commit 6f5907b244

View File

@@ -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++) {