fork 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. private static int[] frontMul(int[] t)
  11. {
  12. int[] r = new int[t.length];
  13. int mul = 1;
  14. for (int i = 0; i < r.length; ++i) {
  15. r[i] = mul;
  16. mul *= t[i];
  17. }
  18. return r;
  19. }
  20.  
  21. private static int[] backMul(int[] t)
  22. {
  23. int[] r = new int[t.length];
  24. int mul = 1;
  25. for (int i = r.length - 1; i >=0; --i) {
  26. r[i] = mul;
  27. mul *= t[i];
  28. }
  29. return r;
  30. }
  31.  
  32. private static int[] solveMullAllButI(int[] t)
  33. {
  34. int[] front = frontMul(t);
  35. int[] back = backMul(t);
  36. int[] r = new int[t.length];
  37.  
  38. for (int i = 0; i < r.length; ++i) {
  39. r[i] = front[i] * back[i];
  40. }
  41. return r;
  42. }
  43.  
  44. public static void main (String[] args) throws java.lang.Exception
  45. {
  46. int[] result = solveMullAllButI(new int[]{1, 2, 3, 4, 5});
  47.  
  48. for(int i = 0; i < result.length; i++) {
  49. System.out.println(result[i]);
  50. }
  51. }
  52. }
Success #stdin #stdout 0.07s 47360KB
stdin
Standard input is empty
stdout
120
60
40
30
24