Upload files to "java/reverse"

This commit is contained in:
2026-04-13 10:44:19 +03:00
parent 84c5957a91
commit 40ad66fb29
5 changed files with 322 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
package reverse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @author Nikita Doschennikov (me@fymio.us)
*/
public class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = null;
int pos = 0;
boolean hasNextLine() throws IOException {
if (line != null && pos < line.length()) return true;
line = br.readLine();
pos = 0;
return line != null;
}
boolean hasNextInt() {
if (line == null) return false;
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++;
}
return (
pos < line.length() &&
(Character.isDigit(line.charAt(pos)) || line.charAt(pos) == '-')
);
}
int nextInt() {
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;
boolean negative = line.charAt(pos) == '-';
if (negative) pos++;
while (pos < line.length() && Character.isDigit(line.charAt(pos))) {
pos++;
}
int result = 0;
for (int i = negative ? start + 1 : start; i < pos; i++) {
result = result * 10 + (line.charAt(i) - '0');
}
return negative ? -result : result;
}
void nextLine() {
pos = line.length();
}
}