void getNumber1(string str, int pos, vector& vec) { for (int i = 0; i < 3; i++) { switch(i) { case 0: { string tem_str = str; char a[10]; memset(a, 0, 10); itoa(pos, a, 10); int mypos = str.find(a); str.insert(mypos, ""); if (pos == 9) { vec.push_back(str); str = tem_str; break; } getNumber1(str, pos + 1, vec); str = tem_str; break; } case 1: { string tem_str = str; char a[10]; memset(a, 0, 10); itoa(pos, a, 10); int mypos = str.find(a); str.insert(mypos, "-"); if (pos == 9) { vec.push_back(str); str = tem_str; break; } getNumber1(str, pos + 1, vec); str = tem_str; break; } case 2: { string tem_str = str; char a[10]; memset(a, 0, 10); itoa(pos, a, 10); int mypos = str.find(a); str.insert(mypos, "+"); if (pos == 9) { vec.push_back(str); str = tem_str; break; } getNumber1(str, pos + 1, vec); str = tem_str; break; } default: break; } } if (pos == 8) { return; } } void main() { vector vec; getNumber1(string("123456789"), 1, vec); vector result; for (int i =0; i < vec.size(); i++) { if (i == 18062) { int m =0; } string str = vec[i]; vector tem_vec; int count = 0; int flag = 1; while (str.find("+") != string::npos||str.find("-") != string::npos) { int pos = str.find_first_of("+"); int pos1 = str.find_first_of("-"); int rpos = 0; if (pos1 >= 0&& pos >= 0) { if (pos > pos1) { rpos = pos1; }else { rpos = pos; } }else { if (pos > pos1) { rpos = pos; }else { rpos = pos1; } } int tem = atoi(str.c_str()); tem_vec.push_back(tem); char ch[10]; memset(ch, 0, 10); char* p = itoa(tem, ch, 10); int size = strlen(p); p[0] = p[size - 1]; p[1] = '\0'; int mypos = str.find_first_of(p); str = str.substr(mypos + 1); } for (int i = 0; i < tem_vec.size(); i++) { count+= tem_vec[i]; } if (count == 100) { result.push_back(vec[i]); } } }