Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 38 additions & 22 deletions src/main/java/algorithms/sprint3/FastSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

public class FastSort {

private static final int MAX_PARTICIPANTS = 100_000;
private static final int MAX_LOGIN_LENGTH = 256;

/*
Принцип работы алгоритма:
1) Считываем n участников в массив.
Expand Down Expand Up @@ -140,51 +143,64 @@ private int read() throws IOException {
return buffer[ptr++];
}

int nextInt() throws IOException {
int c;
do {
c = read();
if (c == -1) {
throw new EOFException();
}
} while (c <= ' ');

int nextInt(String fieldName, int minValue, int maxValue) throws IOException {
int c = nextNonWhitespace();
int value = 0;

while (c > ' ') {
value = value * 10 + c - '0';
if (c < '0' || c > '9') {
throw new IOException("Invalid integer token for " + fieldName);
}
int digit = c - '0';
if (value > (maxValue - digit) / 10) {
throw new IOException("Integer token for " + fieldName + " exceeds " + maxValue);
}
value = value * 10 + digit;
c = read();
}

if (value < minValue) {
throw new IOException("Integer token for " + fieldName + " is below " + minValue);
}
return value;
}

String next() throws IOException {
String next(int maxLength) throws IOException {
int c = nextNonWhitespace();
StringBuilder sb = new StringBuilder(Math.min(maxLength, 16));

while (c > ' ') {
if (sb.length() == maxLength) {
throw new IOException("Token length exceeds " + maxLength);
}
sb.append((char) c);
c = read();
}
return sb.toString();
}

private int nextNonWhitespace() throws IOException {
int c;
do {
c = read();
if (c == -1) {
throw new EOFException();
}
} while (c <= ' ');

StringBuilder sb = new StringBuilder();
while (c > ' ') {
sb.append((char) c);
c = read();
}
return sb.toString();
return c;
}
}

private static void run() throws Exception {
FastIn in = new FastIn(System.in);

int n = in.nextInt(); // n — количество участников
int n = in.nextInt("participant count", 0, MAX_PARTICIPANTS); // n — количество участников
Participant[] participants = new Participant[n];

for (int i = 0; i < n; i++) {
String login = in.next();
int solved = in.nextInt();
int penalty = in.nextInt();
String login = in.next(MAX_LOGIN_LENGTH);
int solved = in.nextInt("solved", 0, Integer.MAX_VALUE);
int penalty = in.nextInt("penalty", 0, Integer.MAX_VALUE);
participants[i] = new Participant(login, solved, penalty);
}

Expand Down