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. int cnt = 0;
  14. for (int i = 12345; i <= 54321; i++) {
  15.  
  16. if (isOk(i)) {
  17. cnt++;
  18. System.out.printf("%3d: %d %s\n", cnt, i, ana(i));
  19. }
  20.  
  21. }
  22. }
  23.  
  24. static boolean isOk(int v) {
  25. int c = 0;
  26. while (v > 0) {
  27. c |= 1 << (v % 10);
  28. v /= 10;
  29. }
  30. return c == ((1 << 1)|(1 << 2)|(1 << 3)|(1 << 4)|(1 << 5));
  31. }
  32.  
  33. static String ana(int v) {
  34. int[] arr = new int[5];
  35. for (int i = 0; i < 5; i++) {
  36. arr[4-i] = v % 10;
  37. v /= 10;
  38. }
  39. int rh = 0, rc = 0, lh = 0, lc = 0;
  40. for (int i = 0; i < 5; i++) {
  41. if (arr[i] > lh) {
  42. lh = arr[i];
  43. lc++;
  44. }
  45. if (arr[4-i] > rh) {
  46. rh = arr[4-i];
  47. rc++;
  48. }
  49. }
  50. return String.format("%d %d", lc, rc);
  51. }
  52. }
Success #stdin #stdout 0.16s 54924KB
stdin
Standard input is empty
stdout
  1: 12345 5 1
  2: 12354 4 2
  3: 12435 4 1
  4: 12453 4 2
  5: 12534 3 2
  6: 12543 3 3
  7: 13245 4 1
  8: 13254 3 2
  9: 13425 4 1
 10: 13452 4 2
 11: 13524 3 2
 12: 13542 3 3
 13: 14235 3 1
 14: 14253 3 2
 15: 14325 3 1
 16: 14352 3 2
 17: 14523 3 2
 18: 14532 3 3
 19: 15234 2 2
 20: 15243 2 3
 21: 15324 2 2
 22: 15342 2 3
 23: 15423 2 3
 24: 15432 2 4
 25: 21345 4 1
 26: 21354 3 2
 27: 21435 3 1
 28: 21453 3 2
 29: 21534 2 2
 30: 21543 2 3
 31: 23145 4 1
 32: 23154 3 2
 33: 23415 4 1
 34: 23451 4 2
 35: 23514 3 2
 36: 23541 3 3
 37: 24135 3 1
 38: 24153 3 2
 39: 24315 3 1
 40: 24351 3 2
 41: 24513 3 2
 42: 24531 3 3
 43: 25134 2 2
 44: 25143 2 3
 45: 25314 2 2
 46: 25341 2 3
 47: 25413 2 3
 48: 25431 2 4
 49: 31245 3 1
 50: 31254 2 2
 51: 31425 3 1
 52: 31452 3 2
 53: 31524 2 2
 54: 31542 2 3
 55: 32145 3 1
 56: 32154 2 2
 57: 32415 3 1
 58: 32451 3 2
 59: 32514 2 2
 60: 32541 2 3
 61: 34125 3 1
 62: 34152 3 2
 63: 34215 3 1
 64: 34251 3 2
 65: 34512 3 2
 66: 34521 3 3
 67: 35124 2 2
 68: 35142 2 3
 69: 35214 2 2
 70: 35241 2 3
 71: 35412 2 3
 72: 35421 2 4
 73: 41235 2 1
 74: 41253 2 2
 75: 41325 2 1
 76: 41352 2 2
 77: 41523 2 2
 78: 41532 2 3
 79: 42135 2 1
 80: 42153 2 2
 81: 42315 2 1
 82: 42351 2 2
 83: 42513 2 2
 84: 42531 2 3
 85: 43125 2 1
 86: 43152 2 2
 87: 43215 2 1
 88: 43251 2 2
 89: 43512 2 2
 90: 43521 2 3
 91: 45123 2 2
 92: 45132 2 3
 93: 45213 2 2
 94: 45231 2 3
 95: 45312 2 3
 96: 45321 2 4
 97: 51234 1 2
 98: 51243 1 3
 99: 51324 1 2
100: 51342 1 3
101: 51423 1 3
102: 51432 1 4
103: 52134 1 2
104: 52143 1 3
105: 52314 1 2
106: 52341 1 3
107: 52413 1 3
108: 52431 1 4
109: 53124 1 2
110: 53142 1 3
111: 53214 1 2
112: 53241 1 3
113: 53412 1 3
114: 53421 1 4
115: 54123 1 3
116: 54132 1 4
117: 54213 1 3
118: 54231 1 4
119: 54312 1 4
120: 54321 1 5