void solveSudoku(vector<vector<char> > &board) { // Start typing your C/C++ solution below // DO NOT write int main() function empties.clear(); memset(row, 0, sizeof(row)); memset(col, 0, sizeof(col)); memset(box, 0, sizeof(box)); for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++) if (board[i][j] == '.') empties.push_back(make_pair(i, j)); else setinfo(i, j, board[i][j] - '0'); solve(board, 0); }
bool solve(vector<vector<char> > &board, int count) { if (count == empties.size()) return true; int i = empties[count].first; int j = empties[count].second; for (int v = 1; v <= 9; v++) { if (ok(i, j, v)) { setinfo(i, j, v); board[i][j] = (v + '0'); if (solve(board, count + 1)) return true; unsetinfo(i, j, v); board[i][j] = '.'; } } return false; }
int iuplua_open(lua_State * L) { int ret; struct luaL_Reg funcs[] = { {"key_open", iupkey_open}, {"Open", il_open}, {"Close", iuplua_close}, {"SetIdle", SetIdle}, {"GetFromC", GetFromC}, {"GetWidget", GetWidget}, {"SetWidget", SetWidget}, {"NewClass", NewClass}, {"SetClass", SetClass}, {"GetClass", GetClass}, {"IsContainer", IsContainer}, {"SetMethod", SetMethod}, {"SetCallback", SetCallback}, {"SetFunction", SetFunction}, {"ihandle_compare", ihandle_compare}, {"ihandle_tostring", ihandle_tostring}, {"_ERRORMESSAGE", il_error_message}, {"dostring", il_dostring}, {"dofile", il_dofile}, { "StringCompare", StringCompare }, { NULL, NULL }, }; if (!il_open(L)) return 0; ret = (int)lua_tointeger(L, -1); /* retrieve IupOpen return value */ lua_pop(L, -1); /* Registers functions in iup namespace */ iuplua_register_lib(L, funcs); /* leave global table at the top of the stack */ iupluaapi_open(L); /* set version info */ setinfo(L); /* register if IupOpen was called here or from outside IupLua */ /* iup._IUPOPEN_CALL = EXTERNAL|INTERNAL */ if (ret == IUP_OPENED) lua_pushliteral (L, "EXTERNAL"); else lua_pushliteral (L, "INTERNAL"); lua_setfield(L, -2, "_IUPOPEN_CALL"); /* used by Idle in Lua */ IupSetGlobal("_IUP_LUA_DEFAULT_STATE", (char *) L); #ifdef IUPLUA_USELOH #include "iuplua.loh" #include "constants.loh" #else #ifdef IUPLUA_USELH #include "iuplua.lh" #include "constants.lh" #else iuplua_dofile(L, "iuplua.lua"); iuplua_dofile(L, "constants.lua"); #endif #endif /* Register the common callbacks */ iuplua_register_cb(L, "HELP_CB", (lua_CFunction)help_cb, NULL); iuplua_register_cb(L, "GETFOCUS_CB", (lua_CFunction)getfocus_cb, NULL); iuplua_register_cb(L, "K_ANY", (lua_CFunction)k_any, NULL); iuplua_register_cb(L, "KILLFOCUS_CB", (lua_CFunction)killfocus_cb, NULL); iuplua_register_cb(L, "MULTITOUCH_CB", (lua_CFunction)multitouch_cb, NULL); /* Register global callbacks */ iuplua_register_cb(L, "GLOBALWHEEL_CB", (lua_CFunction)globalwheel_cb, NULL); iuplua_register_cb(L, "GLOBALBUTTON_CB", (lua_CFunction)globalbutton_cb, NULL); iuplua_register_cb(L, "GLOBALMOTION_CB", (lua_CFunction)globalmotion_cb, NULL); iuplua_register_cb(L, "GLOBALKEYPRESS_CB", (lua_CFunction)globalkeypress_cb, NULL); iuplua_register_cb(L, "GLOBALCTRLFUNC_CB", (lua_CFunction)globalctrlfunc_cb, NULL); iuplua_register_cb(L, "IDLE_ACTION", (lua_CFunction)globalidle_cb, NULL); /* Register Keys */ iupKeyForEach(register_key, (void*)L); /* Iup Modules initialization */ iupbuttonlua_open(L); iupluadraw_open(L); /* must be before canvas */ iupcanvaslua_open(L); iupdialoglua_open(L); iupfilllua_open(L); iupframelua_open(L); iupfiledlglua_open(L); iuphboxlua_open(L); iupitemlua_open(L); iupimagelua_open(L); iuplabellua_open(L); iuplistlua_open(L); iupmenulua_open(L); iupmultilinelua_open(L); iupradiolua_open(L); iupseparatorlua_open(L); iupsubmenulua_open(L); iuptextlua_open(L); iuptogglelua_open(L); iupvboxlua_open(L); iupzboxlua_open(L); iuptimerlua_open(L); iupsboxlua_open(L); iupsplitlua_open(L); iupspinlua_open(L); iupspinboxlua_open(L); iupscrollboxlua_open(L); iupgridboxlua_open(L); iupmultiboxlua_open(L); iupexpanderlua_open(L); iuplinklua_open(L); iupcboxlua_open(L); iupdetachboxlua_open(L); iupbackgroundboxlua_open(L); iupgclua_open(L); iupgetparamlua_open(L); iupvallua_open(L); iuptabslua_open(L); iupfontdlglua_open(L); iupmessagedlglua_open(L); iupcolordlglua_open(L); iupimagergbalua_open(L); iupimagergblua_open(L); iupprogressbarlua_open(L); iupnormalizerlua_open(L); iupuserlua_open(L); iuptreelua_open(L); iupclipboardlua_open(L); iupprogressdlglua_open(L); iupflatlabellua_open(L); iupflatbuttonlua_open(L); iupflattogglelua_open(L); iupdropbuttonlua_open(L); iupflatframelua_open(L); iupflatseparatorlua_open(L); iupspacelua_open(L); iupconfiglua_open(L); iupanimatedlabellua_open(L); iupcalendarlua_open(L); iupdatepicklua_open(L); iupflattabslua_open(L); iupflatscrollboxlua_open(L); iupgaugelua_open(L); iupdiallua_open(L); iupcolorbarlua_open(L); iupcolorbrowserlua_open(L); return 0; /* nothing in stack */ }
int iuplua_open(void) { struct FuncList { char *name; lua_CFunction func; } FuncList[] = { { "IupSetIdle", IupSetIdle }, }; int SizeFuncList = (sizeof(FuncList)/sizeof(struct FuncList)); int i; iuplua_tag = lua_newtag(); lua_pushnumber(iuplua_tag); lua_setglobal("iuplua_tag"); iuplua_namespace = lua_createtable(); lua_pushobject(iuplua_namespace); lua_setglobal ("iup"); setinfo(); for (i = 0; i < SizeFuncList; i++) iuplua_register(FuncList[i].name, FuncList[i].func); lua_register("iup_gettable", iuplua_gettable); lua_register("iup_settable", iuplua_settable); lua_register("iup_index", iuplua_index); lua_register("iupSetCallback", iuplua_set_callback); iupKeyForEach(register_key, NULL); iupluaapi_open(); #ifdef IUPLUA_USELOH #ifdef TEC_BIGENDIAN #ifdef TEC_64 #include "loh/iuplua_be64.loh" #include "loh/constants_be64.loh" #else #include "loh/iuplua_be32.loh" #include "loh/constants_be32.loh" #endif #else #ifdef TEC_64 #ifdef WIN64 #include "loh/iuplua_le64w.loh" #include "loh/constants_le64w.loh" #else #include "loh/iuplua_le64.loh" #include "loh/constants_le64.loh" #endif #else #include "loh/iuplua.loh" #include "loh/constants.loh" #endif #endif #else iuplua_dofile("iuplua.lua"); iuplua_dofile("constants.lua"); #endif iupluawidgets_open(iuplua_tag); sboxlua_open(); spinlua_open(); cboxlua_open(); vallua_open(); tabslua_open(); gclua_open(); getparamlua_open(); treelua_open(); return 1; }
BOOL CtxtDoc::OnOpenDocument(LPCTSTR lpszPathName) { //转换成unicode CFile bb; bb.Open(lpszPathName,CFile::modeReadWrite|CFile::modeRead); byte head[2]; bb.Read(head,2); CString contenttext; if(!((head[0]==0xff&&head[1]==0xfe)||(head[0]==0xfe&&head[1]==0xff))) { try { bb.SeekToBegin(); //文件非unicode ULONGLONG lg=bb.GetLength(); char* pbuf; pbuf=new char[lg+1]; memset(pbuf, '\0', lg+1); int i=bb.Read(pbuf,lg); //ansi to unicode size_t len=strlen(pbuf); int wlen=MultiByteToWideChar(CP_ACP,NULL,pbuf,-1,NULL,NULL); wchar_t *pwText=new wchar_t[wlen]; if(!pwText) { delete []pwText; } MultiByteToWideChar(CP_ACP,0,pbuf,-1,pwText,wlen); contenttext.Format(_T("%s"),pwText); bb.SetLength(0); DWORD h=0xfeff; //bb.Write(_T("fffe"),2); bb.Write(&h,2); bb.Write(contenttext,wlen*2); delete []pwText; delete []pbuf; this->m_isANSI=TRUE; } catch (CFileException* e) { TCHAR szCause[255]; e->GetErrorMessage(szCause, 255); AfxMessageBox(szCause); e->ReportError (); e->Delete (); return 0; } } else { //bb.SeekToBegin(); long len=bb.GetLength(); wchar_t *pwText=new wchar_t[len+1]; memset(pwText,'\0',len+1); bb.Read(pwText,len); contenttext.Format(_T("%s"),pwText); } //contenttext.ReleaseBuffer(); bb.Close(); if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; this->GetView()->DeleteContents(); this->GetView()->SetWindowTextW(contenttext.GetBuffer()); contenttext.ReleaseBuffer(); //this->GetView()->SetWindowTextW(contenttext.GetBuffer()); //contenttext.ReleaseBuffer(); // TODO: 在此添加您专用的创建代码 this->SetModifiedFlag(FALSE); CInputDB setinfo(this); setinfo.m_getinfo(lpszPathName,_T("txt")); return TRUE; }
int main(int argc, char *argv[]) { extern int optind; extern char *optarg; enum S command, state; DB *dbp; DBT data, key, keydata; size_t len; int ch, oflags, sflag; char *fname, *infoarg, *p, *t, buf[8 * 1024]; infoarg = NULL; fname = NULL; oflags = O_CREAT | O_RDWR; sflag = 0; while ((ch = getopt(argc, argv, "f:i:lo:s")) != -1) switch (ch) { case 'f': fname = optarg; break; case 'i': infoarg = optarg; break; case 'l': oflags |= DB_LOCK; break; case 'o': if ((ofd = open(optarg, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) err("%s: %s", optarg, strerror(errno)); break; case 's': sflag = 1; break; case '?': default: usage(); } argc -= optind; argv += optind; if (argc != 2) usage(); /* Set the type. */ type = dbtype(*argv++); /* Open the descriptor file. */ if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) err("%s: %s", *argv, strerror(errno)); /* Set up the db structure as necessary. */ if (infoarg == NULL) infop = NULL; else for (p = strtok(infoarg, ",\t "); p != NULL; p = strtok(0, ",\t ")) if (*p != '\0') infop = setinfo(type, p); /* * Open the DB. Delete any preexisting copy, you almost never * want it around, and it often screws up tests. */ if (fname == NULL) { p = getenv("TMPDIR"); if (p == NULL) p = "/var/tmp"; snprintf(buf, sizeof(buf), "%s/__dbtest", p); fname = buf; unlink(buf); } else if (!sflag) unlink(fname); if ((dbp = dbopen(fname, oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) err("dbopen: %s", strerror(errno)); XXdbp = dbp; state = COMMAND; for (lineno = 1; (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { /* Delete the newline, displaying the key/data is easier. */ if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL) *t = '\0'; if ((len = strlen(buf)) == 0 || isspace(*p) || *p == '#') continue; /* Convenient gdb break point. */ if (XXlineno == lineno) XXlineno = 1; switch (*p) { case 'c': /* compare */ if (state != COMMAND) err("line %lu: not expecting command", lineno); state = KEY; command = COMPARE; break; case 'e': /* echo */ if (state != COMMAND) err("line %lu: not expecting command", lineno); /* Don't display the newline, if CR at EOL. */ if (p[len - 2] == '\r') --len; if (write(ofd, p + 1, len - 1) != len - 1 || write(ofd, "\n", 1) != 1) err("write: %s", strerror(errno)); break; case 'g': /* get */ if (state != COMMAND) err("line %lu: not expecting command", lineno); state = KEY; command = GET; break; case 'p': /* put */ if (state != COMMAND) err("line %lu: not expecting command", lineno); state = KEY; command = PUT; break; case 'r': /* remove */ if (state != COMMAND) err("line %lu: not expecting command", lineno); if (flags == R_CURSOR) { rem(dbp, &key); state = COMMAND; } else { state = KEY; command = REMOVE; } break; case 'S': /* sync */ if (state != COMMAND) err("line %lu: not expecting command", lineno); synk(dbp); state = COMMAND; break; case 's': /* seq */ if (state != COMMAND) err("line %lu: not expecting command", lineno); if (flags == R_CURSOR) { state = KEY; command = SEQ; } else seq(dbp, &key); break; case 'f': flags = setflags(p + 1); break; case 'D': /* data file */ if (state != DATA) err("line %lu: not expecting data", lineno); data.data = rfile(p + 1, &data.size); goto ldata; case 'd': /* data */ if (state != DATA) err("line %lu: not expecting data", lineno); data.data = xmalloc(p + 1, len - 1); data.size = len - 1; ldata: switch (command) { case COMPARE: compare(&keydata, &data); break; case PUT: put(dbp, &key, &data); break; default: err("line %lu: command doesn't take data", lineno); } if (type != DB_RECNO) free(key.data); free(data.data); state = COMMAND; break; case 'K': /* key file */ if (state != KEY) err("line %lu: not expecting a key", lineno); if (type == DB_RECNO) err("line %lu: 'K' not available for recno", lineno); key.data = rfile(p + 1, &key.size); goto lkey; case 'k': /* key */ if (state != KEY) err("line %lu: not expecting a key", lineno); if (type == DB_RECNO) { static recno_t recno; recno = atoi(p + 1); key.data = &recno; key.size = sizeof(recno); } else { key.data = xmalloc(p + 1, len - 1); key.size = len - 1; } lkey: switch (command) { case COMPARE: getdata(dbp, &key, &keydata); state = DATA; break; case GET: get(dbp, &key); if (type != DB_RECNO) free(key.data); state = COMMAND; break; case PUT: state = DATA; break; case REMOVE: rem(dbp, &key); if ((type != DB_RECNO) && (flags != R_CURSOR)) free(key.data); state = COMMAND; break; case SEQ: seq(dbp, &key); if ((type != DB_RECNO) && (flags != R_CURSOR)) free(key.data); state = COMMAND; break; default: err("line %lu: command doesn't take a key", lineno); } break; case 'o': dump(dbp, p[1] == 'r'); break; default: err("line %lu: %s: unknown command character", lineno, p); } } #ifdef STATISTICS /* * -l must be used (DB_LOCK must be set) for this to be * used, otherwise a page will be locked and it will fail. */ if (type == DB_BTREE && oflags & DB_LOCK) __bt_stat(dbp); #endif if (dbp->close(dbp)) err("db->close: %s", strerror(errno)); close(ofd); exit(0); }
INTEGER setinfo_(char *record) { return (setinfo(fcstring(record))); }