fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. public class Main
  7. {
  8. public static final String ROCKSYMBOL = "▓";
  9. public static final String WATERSYMBOL = "▒";
  10. public static final String AIRSYMBOL = "░";
  11.  
  12. public static void main (String[] args) {
  13. byte [] cliff = {0, 12, 13, 11, 12, 10, 11, 9, 10, 8, 9, 7, 8, 6, 7, 0};
  14. int CLIFFS = cliff.length;
  15. byte [][] matrix = new byte[CLIFFS][CLIFFS];
  16.  
  17. for (int column=0; column<CLIFFS; column++) { //подготовка матрицы для красивого вывода
  18. for (int row=0; row<cliff[column]; row++) {
  19. matrix[column][row] = 1;
  20. }
  21. }
  22.  
  23. for (int row=CLIFFS-1; row>=0; row--) { // красивый вывод
  24. System.out.println();
  25. for (int column=0; column<CLIFFS; column++) {
  26. if (matrix[column][row] == 1) System.out.print(ROCKSYMBOL);
  27. else System.out.print(AIRSYMBOL);
  28. }
  29. }
  30.  
  31. System.out.println();
  32. for (int i = 0; i < CLIFFS; i++){
  33. System.out.format("%2d|", cliff[i]);
  34. }
  35.  
  36. byte max_value = 0;
  37. byte max_pos = 0;
  38. int [] water_value = new int[CLIFFS];
  39.  
  40. for (byte i=0; i<CLIFFS; i++) { // вся логика отсюда и до 68 строки
  41. if (cliff[i] == 0) {
  42. byte i_max_value = 0;
  43. byte i_max_pos = 0;
  44. for (byte j = i; j > max_pos; j--) {
  45. if (cliff[j] < i_max_value) {
  46. water_value[j] = i_max_value - cliff[j];
  47. }
  48. if (cliff[j] >= i_max_value) {
  49. i_max_value = cliff[j];
  50. i_max_pos = j;
  51. water_value[j] = 0;
  52. }
  53. }
  54. i_max_value = 0;
  55. i_max_pos = 0;
  56. max_value = 0;
  57. max_pos = 0;
  58. }
  59. else {
  60. if (cliff[i] >= max_value) {
  61. max_value = cliff[i];
  62. max_pos = i;
  63. }
  64. if (cliff[i] < max_value) {
  65. water_value[i] = max_value - cliff[i];
  66. }
  67. }
  68. }
  69.  
  70. int water = 0;
  71. System.out.println();
  72. for (int i = 0; i < CLIFFS; i++){
  73. water += water_value[i];
  74. System.out.format("%2d|", water_value[i]);
  75. }
  76. System.out.println("\nwater: " + water);
  77. }
  78. }
Success #stdin #stdout 0.09s 380160KB
stdin
Standard input is empty
stdout
░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░
░░▓░░░░░░░░░░░░░
░▓▓░▓░░░░░░░░░░░
░▓▓▓▓░▓░░░░░░░░░
░▓▓▓▓▓▓░▓░░░░░░░
░▓▓▓▓▓▓▓▓░▓░░░░░
░▓▓▓▓▓▓▓▓▓▓░▓░░░
░▓▓▓▓▓▓▓▓▓▓▓▓░▓░
░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░
░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░
░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░
░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░
░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░
░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░
 0|12|13|11|12|10|11| 9|10| 8| 9| 7| 8| 6| 7| 0|
 0| 0| 0| 1| 0| 1| 0| 1| 0| 1| 0| 1| 0| 1| 0| 0|
water: 6