Skip to content

Instantly share code, notes, and snippets.

@thegreatshasha
Created February 5, 2016 13:09
Show Gist options
  • Save thegreatshasha/7912b15fe39e3e67201c to your computer and use it in GitHub Desktop.
Save thegreatshasha/7912b15fe39e3e67201c to your computer and use it in GitHub Desktop.
char op[]={'+','-','*','/'};
bool eval(int a[],int target,int n,int pos,int prev)
{
if(pos == n) {
if(prev == target) {
return true;
}
return false;
}
for(int i=0;i<;4;i++) {
int res = 0;
char ch = op[i];
if(ch == '+') {
res = prev + a[pos];
} else if(ch == '-') {
res = prev - a[pos];
} else if(ch == '*') {
res = prev * a[pos];
} else {
res = prev / a[pos];
}
if( eval(a,target,n,pos+1,res ) )
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment