fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] city1 = {1, 5, 4, 3, 2, 1};
  13. int result1 = getRainVolume(city1);
  14.  
  15. System.out.printf("city1: %d\n", result1);
  16. }
  17.  
  18. static int getRainVolume(int[] wallHeight)
  19. {
  20. int maxHeight = 0;
  21. int maxHeightIndex = 0;
  22. for (int i = 0; i < wallHeight.Length; i++)
  23. if (wallHeight[i] > maxHeight)
  24. {
  25. maxHeight = wallHeight[i];
  26. maxHeightIndex = i;
  27. }
  28. int airLevel = 0;
  29. int rainCollected = 0;
  30. for (int i = 0, curHeight; i < maxHeightIndex; i++)
  31. {
  32. curHeight = wallHeight[i];
  33. if (airLevel < curHeight)
  34. airLevel = curHeight;
  35. else if (airLevel > curHeight)
  36. rainCollected += airLevel - curHeight;
  37. }
  38. airLevel = 0;
  39. for (int i = wallHeight.Length - 1, curHeight; i > maxHeightIndex; i--)
  40. {
  41. curHeight = wallHeight[i];
  42. if (airLevel < curHeight)
  43. airLevel = curHeight;
  44. else if (airLevel > curHeight)
  45. rainCollected += airLevel - curHeight;
  46. }
  47. return rainCollected;
  48. }
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:22: error: cannot find symbol
        for (int i = 0; i < wallHeight.Length; i++)
                                      ^
  symbol:   variable Length
  location: variable wallHeight of type int[]
Main.java:39: error: cannot find symbol
        for (int i = wallHeight.Length - 1, curHeight; i > maxHeightIndex; i--)
                               ^
  symbol:   variable Length
  location: variable wallHeight of type int[]
2 errors
stdout
Standard output is empty