24 point algorithm Java code

xiaoxiao2021-03-05  27

/ * I have a small procedure, logic is a bit confusing, and the annotations are also pitiful, but it should be able to list any equality 24 of the four 1 to 10 calculations that can be used to calculate 24. If you have time, please give a point.

* / public class test24point {public static void main (string [] args) {int index = 0; int TEMP = 0; int Totalsuc = 0; int Numb [] = new int [4]; // the first four number Double Num [] [] = new double [36] [3]; // three number [] = new double [6]; // the number after three steps of cagculating double p [] [] = new Double [6] [8]; Double Q [] [] = new double [3] [7]; //system.out.println (2465% 108); //system.out.println (2465/108); system .out.println ("/") / "ba /"); system.out.println ("/" A / / B / "means /" B / A / "/ n") ; / * For (int h = 0; h <= 9; h ) // Get the first four number for calculating and store inten the array number Numb [4] ;. for (int i = 0; i <= 9 ; i ) for (int J = 0; j <= 9; j ) for (int K = 0; k <= 9; k ) {NUMB [0] = H; NUMB [1] = I; Numb [2] = j; Numb [3] = K;} * / for (int i = 0; i <4; i ) {Numb [i] = integer .PARSEINT (Args [i]);} for (int i = 0; i <3; i ) // Get Two of the market = I 1; J <4; J , Temp ) {p [Temp] [0] = NUMB [I] NUMB [J]; P [Temp] [1] = NUMB [I] - NUMB [ j]; p [Temp] [2] = NUMB [J] - NUMB [I]; P [Temp] [3] = NUMB [I] * NUMB [J]; IF (Numb [J]! = 0) P [TEMP] [4] = NUMB [I] / (Double) NUMB [J]; ELSE P [Temp] [4] = 10000;

IF (NUMB [I]! = 0) P [Temp] [5] = NUMB [J] / (Double) NUMB [I]; ELSE P [Temp] [5] = 10000; Switch (TEMP) {CASE 0: P [Temp] [6] = NUMB [2]; P [Temp] [7] = Numb [3]; Break; Case 1: P [Temp] [6] = Numb [1]; p [Temp] [7 ] = NUMB [3]; Break; Case 2: p [Temp] [6] = Numb [1]; p [Temp] [7] = Numb [2]; Break; Case 3: P [Temp] [6] = NUMB [0]; P [Temp] [7] = Numb [3]; Break; Case 4: P [Temp] [6] = Numb [0]; p [Temp] [7] = Numb [2]; Break; case 5: p [Temp] [6] = NUMB [0]; p [Temp] [7] = Numb [1];}} for (int K = 0, TEM = 0; k <6; k // Get The Possible Three NumBers and Store Into the Array Num [36] [3] for Calculating. FOR (INT L = 0; L <6; L , TEM ) {Num [TEM] [0 ] = p [k] [l]; NUM [TEM] [1] = P [k] [6]; NUM [TEM] [2] = P [k] [7]; for (int T = 2, m = 0, N = 0, TE = 0; T> = 0; T -, TE ) {// Get Two of the Three To Calculate and The Store The New Number INTO THE ARRAY q; M = (T 1)% 3; n = (t 2) % 3; Q [TE] [6] = NUM ​​[TEM] [T]; Q [TE] [0] = NUM ​​[TEM] [M] NUM [TEM] [N]; Q [TE] [1] = NUM ​​[TEM] [M] - NUM [TEM] [N]; Q [TE] [2] = NUM ​​[TEM] [N] - NUM [TEM] [M]; Q [TE] [3] = Num [TEM] [M] * NUM [TEM] [N]; IF (NUM [TEM] [N]! = 0) q [TE] [4] = NUM ​​[TEM] [M] / (Double) Num [TEM ] [N]; ELSE q [TE] [4] = 10000; if (NUM [TEM] [M]! = 0) q [TE] [5] = NUM ​​[TEM] [N] / (Double) NUM [ TEM] [M]; ELSE q [TE] [5] = 10000;} for (int u = 0; u <3; u ) for (int V =

0; V <6; V ) {IF (u == 2) {// we mustimest, so the result string can be be appended rightly. Total [0] = Q [U ] [6] q [u] [V]; Total [1] = q [u] [6] - q [u] [v]; Total [2] = Q [u] [v] - q [u] ] [6]; Total [3] = q [u] [v] * q [u] [6]; if (q [u] [6]! = 0) Total [4] = q [u] [6 ] / (double) q [u] [V] = 10000; if (q [u] [v]! = 0) Total [5] = q [u] [v] / (double) Q [u] [6]; Else Total [5] = 10000;} else {Total [0] = q [u] [v] q [u] [6]; Total [1] = Q [u] [ v] - q [u] [6]; Total [2] = Q [u] [6] - q [u] [v]; Total [3] = Q [u] [v] * q [u] [ 6]; if (q [u] [6]! = 0) Total [4] = q [u] [v] / (double) q [u] [6]; Else Total [4] = 10000; IF q [u] [v]! = 0) Total [5] = Q [u] [6] / (double) q [u] [v]; else total [5] = 10000;} for (int S = 0 ; s <6; s ) { IF (Total [S]> 23.9999 && Total [S] <24.0001) {//system.out.println ("24 !!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!! "); TotalSuc ; // print the expression char x [] = new char [3]; int N0 = index; string expre ="; string Expre1 = ""; int N1 = index / 108; // the first composition and its operator. int N2 = index% 108/6; // the second composition and its operator. int N3 = index% 6;

//// Now Ready to Printout The equations. Switch (N1) {Case 0: Expre = "((A B)"; x [1] = 'c'; x [2] = ' D '; Break; Case 1: Expre = "((ab)"; x [1] =' c '; x [2] =' d '; Break; Case 2: Expre = "((ba)" ; x [1] = 'c'; x [2] = 'd'; Break; Case 3: Expre = "((a * b)"; x [1] = 'c'; x [2] = 'd'; Break; Case 4: Expre = "((A / B)"; x [1] = 'c'; x [2] = 'd'; Break; Case 5: Expre = "((( B / a) "; x [1] = 'c'; x [2] = 'd'; Break; Case 6: Expre =" ((A C) "; x [1] = 'b'; x [2] = 'd'; Break; Case 7: Expre = "((AC)"; x [1] = 'b'; x [2] = 'd'; Break; Case 8: EXPRE = ((CA) "; x [1] = 'b'; x [2] = 'd'; Break; Case 9: Expre =" ((a * c) "; x [1] = 'b' ; x [2] = 'd'; Break; Case 10: Expre = "((a / c)"; x [1] = 'b'; x [2] = 'd'; Break; Case 11: Expre = "((C / A)"; x [1] = 'b'; x [2] = 'd'; Break; Case 12: Expre = "((A D)"; x [1 ] = 'b'; x [2] = 'c'; Break; Case 13: Expre = "((ad)"; x [1] = 'b'; x [2] = 'c' Break; Case 14: Expre = "((DA)"; x [1] = 'b'; x [2] = 'c'; Break; Case 15: Expre = "((A * D)" ; x [1] =

'b'; x [2] = 'c'; Break; Case 16: EXPRE = "((A / D)"; x [1] = 'b'; x [2] = 'c'; BREAK; Case 17: Expre = "((D / A)"; x [1] = 'b'; x [2] = 'c'; Break; Case 18: Expre = "((B C)"; X [1] = 'a'; x [2] = 'd'; Break; Case 19: Expre = "((BC)"; x [1] = 'a'; x [2] = 'd' Break; Case 20: Expre = "((CB)"; x [1] = 'a'; x [2] = 'd'; Break; Case 21: Expre = "((b * c)" ; x [1] = 'a'; x [2] = 'd'; Break; Case 22: Expre = "((b / c)"; x [1] = 'a'; x [2] = 'D'; Break; Case 23: Expre = "((C / B)"; x [1] = 'a'; x [2] = 'd'; Break; Case 24: Expre = "((( B D) "; x [1] = 'a'; x [2] = 'c'; Break; Case 25: Expre =" ((BD) "; x [1] = 'a'; x [ 2] = 'C'; Break; Case 26: Expre = "((DB)"; x [1] = 'a'; x [2] = 'c'; Break; Case 27: Expre = " (B * D) "; x [1] = 'a'; x [2] = 'c'; Break; Case 28: Expre =" ((B / D) "; x [1] = 'a' ; x [2] = 'c'; Break; Case 29: EXPRE = "((D / B)"; x [1] = 'a'; x [2] = 'c'; Break; Case 30: Expre = "((C D)"; x [1] = 'a'; x [2] = 'b'; Break; Case 31: Expre = "((C-D)"; x [1] = 'a'; x [2] = 'b'; Break;

Case 32: Expre = "(DC)"; x [1] = 'a'; x [2] = 'b'; Break; Case 33: Expre = "((C * D)"; x [ 1] = 'a'; x [2] = 'b'; Break; Case 34: Expre = "((C / D)"; x [1] = 'a'; x [2] = 'b' ; Break; Case 35: Expre = "((D / c)"; x [1] = 'a'; x [2] = 'b';} Switch (N2) {case 0: Expre = " " x [1] ") "; x [1] = x [2]; Break; // x [0] and x [1]. Case 1: Expre =" - " x [1] ")"; x [1] = x [2]; Break; case 2: expre = "-" x [1] ")"; x [1] = x [2]; Break; Case 3 : Expre = "*" x [1] ")"; x [1] = x [2]; Break; Case 4: Expre = "/" x [1] ")"; x [ 1] = x [2]; Break; Case 5: Expre = "//" x [1] ")"; x [1] = x [2]; Break; Case 6: Expre = " " x [2] ") "; x [1] = x [1]; Break; // x [2] and x [0]. Case 7: Expre =" - x [2] ")"; x [1] = x [1]; Break; case 8: expre = "-" x [2] ")"; x [1] = x [1]; Break; Case 9 : Expre = "*" x [2] ")"; x [1] = x [1]; Break; Case 10 : Expre = "//" x [2] ")"; x [1] = x [1]; Break; Case 11: Expre = "/" x [2] ")"; x [1] = x [1]; Break;

Case 12: EXPRE1 = X [1] " " x [2] ")") ")"; x [1] = '('; Break; // x [1] and x [2]. Case 13 : Expre1 = x [1] "-" " "; x [1] = '('; Break; Case 14: Expre1 = x [1] "-" X [2] ")"; x [1] = '('; Break; Case 15: Expre1 = x [1] "*" x [2] ")"; x [1] = '('; breaf; case 16: expre1 = x [1] "/" x [2] ")"; x [1] = '('; Break; case 17: expre1 = x [1] "//" x [2] ")" ")"; x [1] = '(';} switch (n3) {case 0: Expre = " " x [1] EXPRE1 Break; Case 1: Expre = "-" x [1] Expre1; Break; Case 2: Expre = "- x [1] Expre1; Break; Case 3: Expre =" * " x [1] expre1; break; case 4: expre =" / " x [1] expre1; break; case 5: expre =" // " x [1] expre1;} Expre1; = Expre.Replace ('a' (char) (NUMB [0] 48)); Expre = Expre.Replace ('b', (char) (NUMB [1] 48)); Expre = Expre.rep LACE ('c', (char) (NUMB [2] 48)); Expre = Expre.Replace ('d' (char) (NUMB [3] 48)); System.out.Println (Expre " ");

转载请注明原文地址:https://www.9cbs.com/read-34418.html

New Post(0)