Files
prog-intro-2025/java/reverse/ReverseMaxC.java
me 8b7b78ee4d
Some checks failed
Fast Reverse Tests / test (push) Failing after 16s
Reverse Tests / test (push) Successful in 5s
Sum Tests / test (push) Successful in 8s
add solution for hw3:3637 & tests in runner
2026-01-30 23:04:13 +05:00

62 lines
1.6 KiB
Java

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 = 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 maxRow = lines[i][j];
for (int k = i + 1; k < linesCount; k++) {
if (lines[k].length > j && lines[k][j] > maxRow) {
maxRow = lines[k][j];
}
}
out.print(maxRow);
}
out.println();
}
return out;
}
}