int main() { CHAR_ITEM charItem[] = { { 'W', -1, true }, { 'D', -1, true }, { 'O', -1, false }, { 'T', -1, false }, { 'G', -1, true }, { 'L', -1, false }, { 'E', -1, false }, { 'C', -1, false }, { 'M', -1, false } }; CHAR_VALUE charValue[] = { {false, 0}, {false, 1}, {false, 2}, {false, 3}, {false, 4}, {false, 5}, {false, 6}, {false, 7}, {false, 8}, {false, 9} }; SearchingResult(charItem, charValue, 0, OnCharListReady); }
int main(void) { CharItem char_item[MAX_CHAR_COUNT] = { {'W', -1, true}, {'D', -1, true}, {'O', -1, false}, {'T', -1, false}, {'G', -1, true}, {'L', -1, false}, {'E', -1, false}, {'C', -1, false}, {'M', -1, false} }; CharValue char_val[MAX_VALUE_COUNT] = { {false, 0}, {false, 1}, {false, 2}, {false, 3}, {false, 4}, {false, 5}, {false, 6}, {false, 7}, {false, 8}, {false, 9}, }; SearchingResult(char_item, char_val, 0); return 0; }
//通过暴力穷举法对每个字符进行匹配后验证 void SearchingResult(CHAR_ITEM ci[], CHAR_VALUE cv[], int index, CharListReadyFuncPtr callback) { int max_char_count = 9; //ci[]的长度 int max_number_count = 10; //0-9 if(index == max_char_count) //如果所有字符都已经匹配上数字,进行验证 { callback(ci); //验证函数 return; } for(int i = 0; i < max_number_count; ++i) { if(IsValueValid(ci[index], cv[i])) //去掉不需要匹配的情况 { cv[i].used = true;/*set used sign*/ ci[index].value = cv[i].value; SearchingResult(ci, cv, index + 1, callback); cv[i].used = false;/*clear used sign*/ } } }