5min to write 10min to debug.
#include
#include
#include
using namespace std;
typedef vector IntList;
int result;
IntList nums;
void Test(IntList::iterator i, int value, string s = "")
{
if (i == nums.end())
{
if (value == result) cout << s << endl;
return;
}
Test(i + 1, value + (*i), s+"+ ");
Test(i + 1, value - (*i), s+"- ");
Test(i + 1, value / (*i), s+"/ ");
Test(i + 1, value * (*i), s+"* ");
return;
}
int main(int argc, char ** argv)
{
nums.resize(6);
for (int i = 0; i < 6; i++)
cin >> nums;
cin >> result;
cout << endl;
Test(nums.begin()+1,nums[0]);
return 0;
}