1. Список говнокодов пользователя ch0sen

    Всего: 1

  2. Java / Говнокод #7547

    +76

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    class PseudoVamp {
    	public int num;
    	public boolean truevamp = false;
    	public int x;
    	public int y;
    	public int n1;
    	public int n2;
    	public int n3;
    	public int n4;
    
    	void breaknsort() {
    		n1 = num % 10;
    		n2 = num / 10 % 10;
    		n3 = num / 100 % 10;
    		n4 = num / 1000;
    		int tmp;
    		for (int i = 0; i < 4; i++) {
    			if (n1 > n2) {
    				tmp = n1;
    				n1 = n2;
    				n2 = tmp;
    			}
    
    			if (n2 > n3) {
    				tmp = n2;
    				n2 = n3;
    				n3 = tmp;
    			}
    
    			if (n3 > n4) {
    				tmp = n3;
    				n3 = n4;
    				n4 = tmp;
    			}
    		}
    	}
    
    	public PseudoVamp(int a, int b) {
    		x = a;
    		y = b;
    		num = x * y;
    		breaknsort();
    	}
    }
    
    public class Test {
    
    	static void checkvamp(PseudoVamp vamp) {
    		int x1 = vamp.x % 10;
    		int x2 = vamp.x / 10;
    
    		int y1 = vamp.y % 10;
    		int y2 = vamp.y / 10;
    
    		int tmp;
    		for (int i = 0; i < 4; i++) {
    			if (x1 > x2) {
    				tmp = x1;
    				x1 = x2;
    				x2 = tmp;
    			}
    
    			if (x2 > y1) {
    				tmp = x2;
    				x2 = y1;
    				y1 = tmp;
    			}
    
    			if (y1 > y2) {
    				tmp = y1;
    				y1 = y2;
    				y2 = tmp;
    			}
    		}
    		if (vamp.n1 == x1 && vamp.n2 == x2 && vamp.n3 == y1 && vamp.n4 == y2)
    			vamp.truevamp = true;
    	}
    
    	public static void main(String[] args) {
    		for (int i = 11; i < 100; i++) {
    			for (int j = 11; j < 100; j++) {
    				PseudoVamp v = new PseudoVamp(i, j);
    				if (v.num < 1000)
    					continue;
    				if (v.num > 9999)
    					return;
    				checkvamp(v);
    				if (v.truevamp)
    				System.out.println(v.x + " * " + v.y + " = " + v.num);
    			}
    		}
    	}
    }

    A vampire number has an even number of digits and is formed by multiplying a pair of numbers containing half the number of digits of the result. The digits are taken from the original number in any order. Pairs of trailing zeroes are not allowed. Examples include:
    1260 = 21 * 60
    1827 = 21 * 87
    2187 = 27 * 81
    Write a program that finds all the 4-digit vampire numbers.
    w/o using of arrays.

    ch0sen, 15 Августа 2011

    Комментарии (43)