24 game game code

xiaoxiao2021-04-08  355

#include #include #include

Double A [24] [4]; Int B [24] [4]; Double Num1, Num2, Num3, Num4

Void initiala () {a [0] [0] = Num1; a [0] [1] = Num2; A [0] [2] = Num3; A [0] [3] = Num4; A [1] [ 0] = Num1; A [1] [1] = Num2; A [1] [2] = Num4; A [1] [3] = Num3; A [2] [0] = Num1; A [2] [ 1] = Num3; A [2] [2] = Num2; A [2] [3] = Num4; A [3] [0] = Num1; A [3] [1] = Num3; A [3] [ 2] = NUM4; A [3] [3] = Num2; A [4] [0] = Num1; A [4] [1] = Num4; A [4] [2] = Num3; a [4] [ 3] = Num2; A [5] [0] = Num1; A [5] [1] = Num4; A [5] [2] = Num2; A [5] [3] = Num3; A [6] [ 0] = Num2; A [6] [1] = Num1; A [6] [2] = Num3; A [6] [3] = Num4; A [7] [0] = Num2; A [7] [ 1] = NUM1; A [7] [2] = Num4; A [7] [3] = Num3; A [8] [0] = Num2; A [8] [1] = Num3; a [8] [ 2] = Num1; A [8] [3] = NUM4; A [9] [0] = Num2; A [9] [1] = Num3; A [9] [2] = Num4; A [9] [ 3] = NUM1; A [10] [0] = Num2; A [10] [1] = Num4; A [10] [2] = Num3; A [10] [3] = Num1; A [11] [ 0] = Num2; A [11] [1] = NUM4; A [11] [2] = Num1; A [11] [3] = Num3; A [12] [0] = Num3; A [12] [ 1] = NUM1; A [12] [2] = Num2; A [12] [3] = Num4; A [13] [0] = Num3; A [13] [1] = Num1; A [13] [ 2] = NUM4; A [13] [3] = Num2; A [14] [0] = Num3; A [14] [1] = Num2; A [14] [2] = Num1; A [14] [ 3] = NUM4; A [15] [0] = Num3; A [15] [1] = Num2; A [15] [2] = Num4; A [15] [3] = Num1; A [16] [ 0] = NUM3; A [16] [1] = Num4; A [1 6] [2] = Num3; A [16] [3] = Num1; A [17] [0] = Num3; A [17] [1] = Num4; A [17] [2] = Num1; A [ 17] [3] = NUM3; A [18] [0] = Num4; A [18] [1] = Num1; A [18] [2] = Num3; A [18] [3] = Num2; 19] [0] = NUM4; A [19] [1] = Num1; A [19] [2] = Num2; A [19] [3] = Num3; A [20] [0] = Num4; A [ 20] [1] = Num2; A [20] [2] = Num3; A [20] [3] = Num1; A [21] [0] = NUM4; A [21] [1] = Num2; A [ 21] [2] = Num1; A [21] [3] = Num3; A [22] [0] = Num4; A [22] [1] = Num3; A [22] [2] = Num1;

A [22] [3] = Num2; A [23] [0] = NUM4; A [23] [1] = Num3; A [23] [2] = Num2; A [23] [3] = Num1; } void main () {INT i = 0; int K = 0; int K = 0; int m = 0; BOOL flag = false; double MID1, MID2, MID3; COUT << "input four numbers, with space separation Open (such as 2 7 7 10): "; cin >> Num1 >> Num2 >> Num3 >> Num4; Initiala ();

For (i = 0; i <24; i ) {Num1 = a [i] [0]; Num2 = a [i] [1]; Num3 = a [i] [2]; Num4 = a [i] [ 3]; for (j = 1; j <5; j ) {switch (j) {case 1: mid1 = Num1 Num2; Break; case 2: mid1 = Num1-Num2; Break; Case 3: MID1 = Num1 * Num2; Break; Case 4: MID1 = Num1 / Num2; Break; default: goto loop;} for (k = 1; k <5; k ) {switch (k) {Case 1: MID2 = Num3 MID1; Break; Case 2: MID2 = MID1-Num3; Break; Case 3: MID2 = Num3 * MID1; Break; Case 4: MID2 = MID1 / Num3; Break; Default: goto loop;} for (m = 1; m ) {Switch (m) {case 1: MID3 = MID2 NUM4; Break; case 2: MID3 = MID2-Num4; Break; Case 3: MID3 = MID2 * Num4; Break; Case 4: MID3 = MID2 / Num4; Break Default: goto loop;} if (MID3 == 24 || MID3 == - 24) {flag = true; goto loop;} =} ((MID3 == 1.0 / 24 || MID3 == - 1.0 / 24) && m == 4) {flag = true; goto loop;}} // form} // fork} // forj} // fori cout << " SECOND MONTHD "<< endl; for (i = 0; i <24; i ) // Num1, Num2 **** Num3, Num4 {Num1 = a [i] [0]; Num2 = a [i] [1 ]; Num3 = a [i] [2]; NUM4 = a [i] [3]; for (j = 1; j <5; j ) {switch (j) {case 1: mid1 = Num1 Num2; Break Case 2: MID1 = Num1-Num2; Break; Case 3: MID1 = Num1 * Num2; Break; Case 4: MID1 = Num1 / Num2; Break; Default: goto loop;} for (k = 1; k <5; K ) {Switch (k) {case 1: MID2 = Num3 Num4; Break; Case 2: MID2 = Num4-Num3; Break;

Case 3: MID2 = Num3 * Num4; Break; Case 4: MID2 = Num4 / Num3; Break; Default: goto loop;} for (m = 1; M <5; M ) {switch (m) {casse 1: MID3 = MID2 MID1; Break; Case 2: MID3 = MID2-MID1; Break; Case 3: MID3 = MID2 * MID1; Break; Case 4: MID3 = MID2 / MID1; Break; Default: goto loop;} IF (MID3 = = 24 || MID3 == - 24) {Flag = true; goto loop1;} IF ((MID3 == 1.0 / 24 || MID3 == - 1.0 / 24) && m == 4) {flag = true; goto loop1 ;}} // form} // fork} // forj} // fori

Loop: // first. if (! flag) cout << "failed!" << Endl; else {if (MID3 == 24 || MID3 == - 24) {cout << "/ n answer is: (( "; Cout << a [i] [0]; switch (j) {case 1: cout <<" "; break; cas 2: cout <<" - "; break; case 3: cout <<" * "; Break; Case 4: cout <<" / "; break; default: cout <<"; break;} cout << a [i] [1] << ")"; switch (k) {cas 1 : cout << " "; Break; Case 2: cout << "-"; break; cas 3: cout << "*"; break; case 4: cout << "/"; break; default: cout < <""; Break;} cout << a [i] [2] << ")"; switch (m) {case 1: cout << " "; breaf; case 2: cout << " Break; Case 3: COUT << "*"; break; cas 4: cout << "/"; break; default: cout << "; break;} cout << a [i] [3] << ENDL GetChar ();} else / 1/24 / {cout << "/ n answer is:"; cout << a [i] [3]; switch (m) {casse 1: cout << " "; Break; Case 2: COUT << "-"; break; cas 3: cout << "*"; break; cas 4: cout << "/"; break; default: cout << "; ban;

COUT << "((" << a [i] [0]; switch (j) {case 1: cout << " "; break; case 2: cout << "-"; break; cas 3: cout << "*"; Break; Case 4: cout << "/"; break; default: cout << "; break;} cout << a [i] [1] <<") "; switch (K ) {Case 1: COUT << " "; break; case 2: cout << "-"; break; cas 3: cout << "*"; break; case 4: cout << "/"; Default: cout << "; Break;} cout << a [i] [2] <<") "<< endl; getchar ();}} loop1: second if (flag) {ix (mid3 == 24 || MID3 == - 24) {cout << "/ n answer is: ("; cout << a [i] [0]; switch (j) {case 1: cout << " "; Break; case 2: COUT << "-"; Break; Case 3: COUT << "*"; break; case 4: cout << "/"; break; default: cout << "; break;} cout << a [i] [1] << ")"; switch (m) {casse 1: cout << " "; break; case 2: cout << "-"; break; case 3: cout << "*" Break; Case 4: COUT << "/"; break; default: cout << "; break;} cout << (" << a [i] [2]; switch (k) {cas 1: COUT << " "; Break; Case 2: cout << "-"; break; casse 3: cout << "*"; BREA K; Case 4: cout << "/"; break; default: cout << "; break;} cout << a [i] [3] <<" << ENDL; getchar (); else / 1/24 / {COUT << "/ n answer is:"; cout << a [i] [3];

Switch (m) {casse 1: cout << " "; break; cas 2: cout << "-"; break; case 3: cout << "*"; break; casse 4: cout << "/" Break; default: cout << ""; break;} cout << "((" << a [i] [0]; switch (j) {case 1: cout << " "; break; casse 2 : COUT << "-"; Break; Case 3: COUT << "*"; break; case 4: cout << "/"; break; default: cout << "; break;} cout << a [ I] [1] << ")"; switch (k) {case 1: cout << " "; break; case 2: cout << "-"; break; cas 3: cout << "*"; Break; case 4: cout << "/"; break; default: cout << "; break;} cout << a [i] [2] <<") "<< Endl; getchar ();}} GetChar ();

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

New Post(0)