diff --git a/.gitea/workflows/reverse.yml b/.gitea/workflows/reverse.yml index 74d269e..de549ee 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 3233 3435 3637 + java -ea -cp out reverse.ReverseTest Base 3233 3435 3637 3839 diff --git a/java/reverse/ReverseMax.java b/java/reverse/ReverseMax.java new file mode 100644 index 0000000..f8c39c9 --- /dev/null +++ b/java/reverse/ReverseMax.java @@ -0,0 +1,63 @@ +package reverse; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; + +public class ReverseMax { + 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 = getPrintWriter(linesCount, lines); + out.flush(); + } + + private static PrintWriter getPrintWriter(int linesCount, int[][] lines) { + PrintWriter out = new PrintWriter(System.out); + + for (int i = 0; i < linesCount; i++) { + int[] line = lines[i]; + + for (int j = 0; j < line.length; j++) { + + if (j > 0) out.print(" "); + + int maxValue = lines[i][j]; + + for (int k = i; k < linesCount; k++) { + for (int m = j; m < lines[k].length; m++) { + if (lines[k][m] > maxValue) { + maxValue = lines[k][m]; + } + } + } + + out.print(maxValue); + } + out.println(); + } + return out; + } +}