Upload files to "java/reverse"
This commit is contained in:
50
java/reverse/ReverseEven.java
Normal file
50
java/reverse/ReverseEven.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package reverse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Nikita Doschennikov (me@fymio.us)
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
66
java/reverse/ReverseMax.java
Normal file
66
java/reverse/ReverseMax.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package reverse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Nikita Doschennikov (me@fymio.us)
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
64
java/reverse/ReverseMaxC.java
Normal file
64
java/reverse/ReverseMaxC.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package reverse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Nikita Doschennikov (me@fymio.us)
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
55
java/reverse/ReverseRotate.java
Normal file
55
java/reverse/ReverseRotate.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package reverse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Nikita Doschennikov (me@fymio.us)
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
68
java/reverse/ReverseSum.java
Normal file
68
java/reverse/ReverseSum.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package reverse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Nikita Doschennikov (me@fymio.us)
|
||||
*/
|
||||
public class ReverseSum {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
printResult(linesCount, lines);
|
||||
}
|
||||
|
||||
private static void printResult(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 sum = 0;
|
||||
|
||||
for (int m = 0; m < lines[i].length; m++) {
|
||||
sum += lines[i][m];
|
||||
}
|
||||
|
||||
for (int k = 0; k < linesCount; k++) {
|
||||
if (k != i && lines[k].length > j) {
|
||||
sum += lines[k][j];
|
||||
}
|
||||
}
|
||||
|
||||
out.print(sum);
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user