Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int cp(int num1, int num2, int type){
- if (type<2){
- if (type==0){
- return num1+num2;
- }else{
- return num1-num2;
- }
- }else{
- if (type==2){
- return num1*num2;
- }else{
- return num1/num2;
- }
- }
- }
- void Find(int number){
- static int rst = number;
- static int arrcp[9];
- if (number == 1){
- if (rst ==2016){
- char p[] = {'+','-','*','/'};
- for (int i=0;i<8;i++){
- cout << i+1 << p[arrcp[i+1]] << "(";
- }
- cout << "9";
- for (int i=0;i<8;i++){
- cout << ")";
- }
- cout << "\n";
- }
- return;
- }
- for (int i=0;i<4;i++){
- int bk = rst;
- if (!(rst==0 && i==3)){
- rst=cp(number-1,rst,i);
- }
- arrcp[number-1]=i;
- Find(number-1);
- rst = bk;
- }
- }
- int main(){
- Find(9);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment