A nice 24-point calculation program

xiaoxiao2021-03-05  36

#include #include #include

Using namespace std;

Const Double precision = 0.00001;

Double Number [4]; String Expression [4];

Bool search (int N) {if (n == 1) {IF (FABS (Number [0] - 24)

For (int i = 0; i

A = Number [i]; b = number [J]; NUMBER [J] = Number [n - 1];

Expa = expression [i]; expb = expression [j]; expression [j] = expression [n - 1];

Expression [I] = '(' EXPA ' ' EXPB ')'; Number [i] = A B; IF (Search (n - 1)) Return True; Expression [i] = '(' EXPA '-' EXPB ')'; Number [i] = a - b; if (Search (N - 1)) Return True; Expression [i] = '(' EXPB '-' EXPA ')'; Number [I] = B - a; IF (Search (n - 1)) Return True;

Expression [i] = '(' EXPA '*' EXPB ')'; Number [i] = a * b; if (Search (n - 1)) Return True;

IF (b! = 0) {Expression [i] = '(' EXPA '/' EXPB ')'; Number [i] = A / B; IF (Search (n - 1)) Return True; } f (a! = 0) {Expression [i] = '(' EXPB '/' EXPA ')'; Number [i] = B / A; IF (Search (n - 1)) Return True }

Number [i] = a; Number [j] = b; expression [i] = expa; expression [j] = expb;}} Return False;

Void main () {cout << "please input four number number: << Endl; for (int i = 0; i <4; i ) {char buffer [20]; int x; cin >> x; Number [i ] = x; ITOA (X, Buffer, 10); Expression [i] = buffer;}

IF (Search (4)) {cout << "Success." << endl;} else {cout << "fail." << endl;}}

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

New Post(0)