---------------------------------------------------------------------------
细节:数字划分与插入运算符逻辑分开
#include<iostream>
#include<vector>
#include<string>
#define maxn 15
using namespace std;
vector<string>res;
vector<int>tmp;
int a[] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 };
void judge(int target,int index,vector<int>&res,string &s) {
if (index == res.size()) {
if (target == 100) {
s = s + "=100";
printf("%s
", s.c_str());
}
return ;
}
int sm = res[index];
//res.pop_back();
for (int i = 0; i < 2; i++) {
if (i == 0) {
string ss = s + "-" + to_string(sm);
judge(target -sm, index + 1, res,ss);
}
else {
string ss = s + "+" + to_string(sm);
judge(target + sm,index+1, res, ss);
}
}
}
void solve( int index) {
if (index == maxn+1) {
string s = to_string(tmp[0]);
judge(tmp[0],1,tmp,s);
return;
}
int sum = 0;
for (int i = index; i <= maxn; i++) {
sum = sum * 10 + a[i];
//s = s + to_string(sum);
tmp.push_back(sum);
//string ss = s + to_string(sum);
solve(i+1);
tmp.pop_back();
}
}
int main() {
string ss = "";
solve(1);
return 0;
}