81 lines
2.4 KiB
Java
81 lines
2.4 KiB
Java
package reverse;
|
|
|
|
import java.io.*;
|
|
import java.util.Arrays;
|
|
|
|
public class Reverse {
|
|
public static void main(String[] args) throws IOException {
|
|
FastScanner sc = new FastScanner();
|
|
int[][] lines = new int[8][];
|
|
int linesCount = 0;
|
|
|
|
while (sc.hasNextLine()) {
|
|
int[] line = new int[8];
|
|
int count = 0;
|
|
|
|
while (sc.hasNextInt()) {
|
|
if (count >= line.length) {
|
|
line = Arrays.copyOf(line, line.length * 2);
|
|
}
|
|
line[count++] = sc.nextInt();
|
|
}
|
|
sc.nextLine();
|
|
|
|
line = Arrays.copyOf(line, count);
|
|
|
|
if (linesCount >= lines.length) {
|
|
lines = Arrays.copyOf(lines, lines.length * 2);
|
|
}
|
|
lines[linesCount++] = line;
|
|
}
|
|
|
|
PrintWriter out = new PrintWriter(System.out);
|
|
for (int i = linesCount - 1; i >= 0; i--) {
|
|
int[] line = lines[i];
|
|
for (int j = line.length - 1; j >= 0; j--) {
|
|
if (j < line.length - 1) out.print(" ");
|
|
out.print(line[j]);
|
|
}
|
|
out.println();
|
|
}
|
|
out.flush();
|
|
}
|
|
|
|
static 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))) pos++;
|
|
return pos < line.length();
|
|
}
|
|
|
|
int nextInt() {
|
|
while (pos < line.length() && Character.isWhitespace(line.charAt(pos))) 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();
|
|
}
|
|
}
|
|
} |