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. // 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;
  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 380224KB
stdin
Standard input is empty
stdout
2 x 2 + 2 = 6
2 x 2 + 3 = 7
2 x 2 + 4 = 8
2 x 2 + 5 = 9
2 x 2 + 6 = 10

2 x 2 + 7 = 11
3 x 3 + 3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