diff --git a/.gitea/workflows/reverse.yml b/.gitea/workflows/reverse.yml index 8731c79..5031fc2 100644 --- a/.gitea/workflows/reverse.yml +++ b/.gitea/workflows/reverse.yml @@ -19,4 +19,4 @@ jobs: - name: Run Sum tests run: | - java -ea -cp out reverse.ReverseTest Base + java -ea -cp out reverse.ReverseTest Base 3233 3435 diff --git a/java/reverse/FastScanner.java b/java/reverse/FastScanner.java new file mode 100644 index 0000000..cf455f7 --- /dev/null +++ b/java/reverse/FastScanner.java @@ -0,0 +1,43 @@ +package reverse; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +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))) 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(); + } +} \ No newline at end of file diff --git a/java/reverse/Reverse.java b/java/reverse/Reverse.java index dff1d1f..5bc07ea 100644 --- a/java/reverse/Reverse.java +++ b/java/reverse/Reverse.java @@ -40,42 +40,4 @@ public class Reverse { } 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(); - } - } } \ No newline at end of file diff --git a/java/reverse/ReverseEven.java b/java/reverse/ReverseEven.java new file mode 100644 index 0000000..b8f6613 --- /dev/null +++ b/java/reverse/ReverseEven.java @@ -0,0 +1,46 @@ +package reverse; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; + +public class ReverseEven { + 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 ((i + j) % 2 == 0) { + if (j < line.length - 1) out.print(" "); + out.print(line[j]); + } + } + out.println(); + } + out.flush(); + } +} diff --git a/java/reverse/ReverseMaxC.java b/java/reverse/ReverseMaxC.java new file mode 100644 index 0000000..4247751 --- /dev/null +++ b/java/reverse/ReverseMaxC.java @@ -0,0 +1,44 @@ +package reverse; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; + +public class ReverseMaxC { + 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(); + } +} diff --git a/java/reverse/ReverseRotate.java b/java/reverse/ReverseRotate.java new file mode 100644 index 0000000..d65a511 --- /dev/null +++ b/java/reverse/ReverseRotate.java @@ -0,0 +1,52 @@ +package reverse; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; + +public class ReverseRotate { + public static void main(String[] args) throws IOException { + FastScanner sc = new FastScanner(); + int[][] lines = new int[8][]; + int linesCount = 0; + int maxCols = 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; + + if (count > maxCols) { + maxCols = count; + } + } + + + PrintWriter out = new PrintWriter(System.out); + + for (int j = 0; j < maxCols; j++) { + for (int i = linesCount - 1; i >= 0; i--) { + if (lines[i].length > j) { + out.print(lines[i][j] + " "); + } + } + out.println(); + } + + out.flush(); + } +} diff --git a/java/reverse/test.dat b/java/reverse/test.dat deleted file mode 100644 index 0177db2..0000000 --- a/java/reverse/test.dat +++ /dev/null @@ -1,2 +0,0 @@ -1 2 -3