Last active
December 27, 2015 23:28
-
-
Save evlogiy/7405717 to your computer and use it in GitHub Desktop.
ОСТОРОЖНО БЫДЛОКОД
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
/* Name of the class has to be "Main" only if the class is public. */ | |
public class Main | |
{ | |
public static final String ROCKSYMBOL = "▓"; | |
public static final String WATERSYMBOL = "▒"; | |
public static final String AIRSYMBOL = "░"; | |
public static void main (String[] args) { | |
byte [] cliff = {0, 12, 13, 11, 12, 10, 11, 9, 10, 8, 9, 7, 8, 6, 7, 0}; | |
int CLIFFS = cliff.length; | |
byte [][] matrix = new byte[CLIFFS][CLIFFS]; | |
for (int column=0; column<CLIFFS; column++) { //подготовка матрицы для красивого вывода | |
for (int row=0; row<cliff[column]; row++) { | |
matrix[column][row] = 1; | |
} | |
} | |
for (int row=CLIFFS-1; row>=0; row--) { // красивый вывод | |
System.out.println(); | |
for (int column=0; column<CLIFFS; column++) { | |
if (matrix[column][row] == 1) System.out.print(ROCKSYMBOL); | |
else System.out.print(AIRSYMBOL); | |
} | |
} | |
System.out.println(); | |
for (int i = 0; i < CLIFFS; i++){ | |
System.out.format("%2d|", cliff[i]); | |
} | |
byte max_value = 0; | |
byte max_pos = 0; | |
int [] water_value = new int[CLIFFS]; | |
for (byte i=0; i<CLIFFS; i++) { // вся логика отсюда и до 68 строки | |
if (cliff[i] == 0) { | |
byte i_max_value = 0; | |
byte i_max_pos = 0; | |
for (byte j = i; j > max_pos; j--) { | |
if (cliff[j] < i_max_value) { | |
water_value[j] = i_max_value - cliff[j]; | |
} | |
if (cliff[j] >= i_max_value) { | |
i_max_value = cliff[j]; | |
i_max_pos = j; | |
water_value[j] = 0; | |
} | |
} | |
i_max_value = 0; | |
i_max_pos = 0; | |
max_value = 0; | |
max_pos = 0; | |
} | |
else { | |
if (cliff[i] >= max_value) { | |
max_value = cliff[i]; | |
max_pos = i; | |
} | |
if (cliff[i] < max_value) { | |
water_value[i] = max_value - cliff[i]; | |
} | |
} | |
} | |
int water = 0; | |
System.out.println(); | |
for (int i = 0; i < CLIFFS; i++){ | |
water += water_value[i]; | |
System.out.format("%2d|", water_value[i]); | |
} | |
System.out.println("\nwater: " + water); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cылка на пост с задачкой: http://habrahabr.ru/post/200190
Ссылка на онлайн джава компилер: http://ideone.com/7fuPD6