1 /************************************************************************/2 /*1 2 3 4 5 6 7 8 9 = 81 Add the subtraction number between 1-9 to set the equation. */3 /************************************************************************/4#include <iostream>5 using namespacestd;6 7 BOOLStop =false;//Control Traversal Termination8 intCount_ =0;//number of calculated results9 intCount_loop =0;//count the number of cyclesTen One voidTransint* Arr,intIndex//increment traversal from right to left A { - if(Index <0) - return; the inttemp = Arr[index]/4; - if(Temp <=0)//Determine if rounding is required - return; -Arr[index] = Arr[index]%4; + if(Index = =0)//determine if you have traversed - { +Stop =true; A return; at } -Arr[index-1] +=temp; -Trans (arr, index-1); - } - - voidShowint* Symbol,intLen//process Each traversal result and display the correct item in { - floatnumber[9]= {1,2,3,4,5,6,7,8,9}; to intsymbol_copy[9]; + for(inti =0; I <9; ++i) - { theSymbol_copy[i] =Symbol[i]; * } $ /*Panax Notoginseng calculates the result with the multiplication number, placing the preceding item at 0, the symbol follows the preceding symbol - */ the for(inti =0; I < Len-1; i++)//Merging multiplication Items + { A if(Symbol_copy[i] = =2|| Symbol_copy[i] = =3) the { + if(Symbol_copy[i] = =2)//calculate the merged results - { $number[i+1] = number[i] * number[i+1]; $ } - Else if(Symbol_copy[i] = =3) - { thenumber[i+1] = Number[i]/number[i+1]; - }WuyiNumber[i] =0;//Merge the previous number 0 the - if(i = =0) WuSymbol_copy[i] =0; - Else AboutSymbol_copy[i] = symbol_copy[i-1];//multiplication result merge, symbol replaced with previous symbol $ } - } - - floatnum = number[0]; A for(inti =0; I < Len-1; ++i)//Calculation Results + { the if(Symbol_copy[i] = =0) -num + = number[i+1]; $ Else if(Symbol_copy[i] = =1) thenum-= number[i+1]; the } the the if(num = =Bayi)//print the correct equation - { incount_++; the for(inti =0; I < Len-1; ++i) the { Aboutcout<<i+1; the if(Symbol[i] = =0) thecout<<"+"; the Else if(Symbol[i] = =1) +cout<<"-"; - Else if(Symbol[i] = =2) thecout<<"*";Bayi Else if(Symbol[i] = =3) thecout<<"/"; the } -cout<<"9=81"<<Endl; - } the } the the the intMain () - { the intsymbol[9] = {0};//[0:+ 1:-2:* 3:/] the intLen =9; the while(!stop)94 { the Show (symbol, Len); thesymbol[len-2]++; theTrans (symbol, len-2);98count_loop++; About } -cout<<"have a"<<count_<<"kind of possible"<<Endl;101cout<<"traversed the"<<count_loop<<"Times"<<Endl;102System"Pause");103 return 0;104}
1 2 3 4 5 6 7 8 9 = 81 Add a subtraction number between 1-9 to set up the equation