/* * Take 5 (via mjd@cs.auckland.ac.nz) */ #include #include #include #include #include // #define DEBUG using namespace std; const static int MAXDIM=10; static int grid[MAXDIM][MAXDIM]; typedef vector vchar; bool isAssigned(string sKey, vchar map) { #ifdef DEBUG cerr << "isAssigned(" << sKey << ")\n"; #endif int n=sKey.size(); for (int i=0; i>(istream& in, Take5& G) { for (int i=0; i<11; i++) G.dict[i].resize(0); G.words.resize(0); int n; in >> n; if (n==0) exit(1); string w; for (int i=0; i> w; G.dict[w.size()].push_back(w); } int c; in >> G.r >> G.c; for (int i=0; i> c; grid[i][j] = c; } } return in; } Take5 me; bool solvePuzzle(int numW, int numC, vchar map) { #ifdef DEBUG cerr << "numW=" << numW << " numC=" << numC << endl; me.printAnswer(map); #endif int totW = me.words.size(); if (numW == totW) { me.printAnswer(map); return true; } vchar Nmap(26); string nextW = me.words[numW]; int lenW = nextW.size(); if (isAssigned(nextW, map) && (find(me.dict[lenW].begin(), me.dict[lenW].end(), assignedWord(nextW, map)) != me.dict[lenW].end() )) { #ifdef DEBUG cerr << "found assignedWord = " << assignedWord(nextW, map) << endl; #endif return solvePuzzle(numW+1, numC, map); } else { for (int i=0; i> me; me.getPuzzleWords(); // cout << me; vchar map(26); for (int i=0; i<26; i++) { map[i]=' '; } assert( solvePuzzle(0, 0, map) ); } }