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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Expression[] exps = new Expression[100];
  14. for (int i = 0; i < exps.length; ++i)
  15. {
  16. exps[i] = null;
  17. }
  18.  
  19. for (int a = 2; a <= 9; ++a)
  20. {
  21. for (int b = 2; b <= 9; ++b)
  22. {
  23. for (int c = 2; c <= 9; ++c)
  24. {
  25. Expression exp = new Expression(a, b, c);
  26. int index = exp.index;
  27. exps[index] = simply(exps[index], exp);
  28. }
  29. }
  30. }
  31.  
  32. for (int i = 0; i < exps.length; ++i)
  33. {
  34. if (exps[i] != null)
  35. {
  36. System.out.println(exps[i]);
  37. if (exps[i].result % 5 == 0)
  38. {
  39. System.out.println();
  40. }
  41. }
  42. }
  43.  
  44.  
  45. }
  46.  
  47. static Expression simply(Expression exp1, Expression exp2)
  48. {
  49. if (exp1 == null) return exp2;
  50. if (exp2 == null) return exp1;
  51. return exp1.simple >= exp2.simple ? exp1 : exp2;
  52. }
  53.  
  54. static class Expression
  55. {
  56. public final int a, b, c, result, simple, index;
  57. public Expression(int a, int b, int c)
  58. {
  59. this.a = a;
  60. this.b = b;
  61. this.c = c;
  62. result = a * b - c;
  63. index = result + 9;
  64. simple = (a == b ? 5 : 0)
  65. + (a == c ? 1 : 0)
  66. + (b == c ? 5 : 0)
  67. + (a <= b && b <= c ? 1 : 0)
  68. + (a >= b && b >= c ? 1 : 0);
  69. }
  70.  
  71. @Override
  72. public String toString()
  73. {
  74. return a + " x " + b + " - " + c + " = " + result;
  75. }
  76. }
  77. }
Success #stdin #stdout 0.08s 381248KB
stdin
Standard input is empty
stdout
2 x 2 - 9 = -5

2 x 2 - 8 = -4
2 x 2 - 7 = -3
2 x 2 - 6 = -2
2 x 2 - 5 = -1
2 x 2 - 4 = 0

2 x 2 - 3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