/* * Play the "animal" game, in which the program attempts to guess an animal * that the user is thinking of by asking yes or no questions. Eventually, * the program either will guess the user's animal or run out of questions * to ask. In the latter case, the program will ask the user to provide a * yes-or-no question that would distinguish between the user's animal and * the program's best guess. * The data structure of questions and guesses is essentially a binary tree, * with each internal node having a "yes" branch and a "no" branch. Leaves * of the tree represent animals to be guessed by the program. If the program * fails to guess the user's animal, it replaces one of the leaves of the tree * by a node containing the new question, whose children are the program's * best guess and the animal provided by the user. * The structure of the program is simple. It initializes the question/guess * data structure, then plays games as long as the user is interested. In each * game, the program starts at the top of the tree (the root) and progresses * toward the bottom (the leaves) depending on the user's responses. Once it * reaches a leaf, it either has won or lost, and handles the situation as * described above. */ int main (int argc, char *argv[]) { char *treefile = NULL; TreeType tree; PositionType pos; char *newQuestion, *newAnswer; if (argc > 1) { treefile = argv[1]; } tree = InitTree (treefile); printf("%s", "Think of an animal. I will try to guess what it is.\n" "Please answer my questions with yes or no.\n"); while (TRUE) { pos = Top (tree); while (!IsLeaf (tree, pos)) { pos = Answer(Question(tree,pos))? YesNode(tree,pos): NoNode(tree,pos); } if (Answer (Guess (tree, pos))) { printf ("I got it right!\n"); } else { GetNewInfo (tree, pos, &newAnswer, &newQuestion); ReplaceNode (tree, pos, newAnswer, newQuestion); } if (!Answer ("Want to play again? ")) { WriteTree(tree, treefile); exit (0); } } }
/* * Play the "animal" game, in which the program attempts to guess an animal * that the user is thinking of by asking yes or no questions. Eventually, * the program either will guess the user's animal or run out of questions * to ask. In the latter case, the program will ask the user to provide a * yes-or-no question that would distinguish between the user's animal and * the program's best guess. * The data structure of questions and guesses is essentially a binary tree, * with each internal node having a "yes" branch and a "no" branch. Leaves * of the tree represent animals to be guessed by the program. If the program * fails to guess the user's animal, it replaces one of the leaves of the tree * by a node containing the new question, whose children are the program's * best guess and the animal provided by the user. * The structure of the program is simple. It initializes the question/guess * data structure, then plays games as long as the user is interested. In each * game, the program starts at the top of the tree (the root) and progresses * toward the bottom (the leaves) depending on the user's responses. Once it * reaches a leaf, it either has won or lost, and handles the situation as * described above. */ int main () { TreeType tree; PositionType pos; char *newQuestion, *newAnswer; tree = InitTree (); // unitTest(); printf("%s", "Think of an animal. I will try to guess what it is.\n" "Please answer my questions with yes or no.\n"); while (TRUE) { pos = Top (tree); while (!IsLeaf (tree, pos)) { pos = Answer (Question (tree, pos))? YesNode (tree, pos): NoNode (tree, pos); } if (Answer (Guess (tree, pos))) { printf ("I got it right!\n"); } else { GetNewInfo (tree, pos, &newAnswer, &newQuestion); ReplaceNode (tree, pos, newAnswer, newQuestion); } if (!Answer ("Want to play again? ")) { exit (0); } } return 0; }
/*********************************** TabMenu Constructor Author: Jamie Gault ***********************************/ TabMenu::TabMenu(WinData *wd): m_isOpen(false), m_action(TMA_NONE), m_windata(wd) { m_pos_y = DATA("TAB_MENU_POSY") - DATA("TAB_OPEN_HT"); m_pause_but = Answer(pText_man, std::string("Pause Game"), DATA("TAB_PBUT_POSX"), DATA("TAB_MENU_POSY")+DATA("TAB_BUT_OFFSETY"), 500.0f ); m_discuss_but = Answer(pText_man, std::string("Discuss"), DATA("TAB_DISCBUT_POSX"), DATA("TAB_MENU_POSY")+DATA("TAB_BUT_OFFSETY"), 500.0f ); //set the string so the box is the right width std::string rndcnt; if( m_windata->rule == BOTH_LIMIT || m_windata->rule == ROUND_LIMIT) rndcnt = std::string("Round 1 out of 10"); else rndcnt = std::string("Round 1"); m_rndDisplay = TextBox(pText_man, rndcnt, DATA("TAB_RNDCNT_POSX"), DATA("TAB_MENU_POSY")+DATA("TAB_BUT_OFFSETY"), 700.0f); SetTurnText(); //setup max score std::stringstream score; score<< "Goal Score is " << m_windata->goal_score << "."; m_scrMax = TextBox(pText_man, score.str(), DATA("TAB_SCRMAX_POSX"), DATA("TAB_MENU_POSY")+DATA("TAB_BUT_OFFSETY"), 500.0f); m_folder = Box_2D(BT_SQUARE, 0.0f, m_pos_y, 1026.0f, 128.0f); m_folder.SetBackGround( pTexture_man->GetTexture("TAB_MENU")); m_tab = Box_2D(BT_LINES, 0.0f, m_pos_y, 250.0f, 68.0f); }
void BftpMaker::add() { Question q; q.setText(tr("empty")); q.addAnswer(Answer(tr("empty"), false)); q.addAnswer(Answer(tr("empty"), false)); q.addAnswer(Answer(tr("empty"), false)); _test.insertQuestion(++_currentQ, q); setQuestion(_currentQ); }
abyss_bool HandleTime(TSession *r) { char z[50]; time_t ltime; TDate date; const char * dateString; const char * answer; if (strcmp(r->uri,"/time")!=0) return FALSE; if (!RequestAuth(r,"Mot de passe","moez","hello")) return TRUE; time(<ime); DateFromGMT(&date, ltime); DateToString(&date, &dateString); xmlrpc_asprintf(&answer, "The time is %s", dateString); Answer(r, 200, answer); xmlrpc_strfree(dateString); xmlrpc_strfree(answer); return TRUE; }
void Outptr(void *pData, uint wSize) { InitPush(0); PushChar(bLogical); PushChar(0); PushChar( (bHEADER + wSize + 2) % 0x100 ); PushChar( (bHEADER + wSize + 2) / 0x100 ); PushChar(bQuery); InitPushCRC(); PushChar( GetCurrHouIndex() ); PushChar( mpibEngCurrTariff[ GetCurrHouIndex() ] ); PushChar( mpibPowCurrTariff[ GetCurrHouIndex() ] ); PushChar(ibSoftMnt); PushIntBig(iwHardHou); PushChar(ibHardDay); PushChar(ibHardMon); PushChar(cbWaitQuery); PushChar(0); MakeCRC16OutBuff(0,bHEADER); switch (ibPort) { case 0: pbData0 = pData; bCRCHi0 = bCRCHi; bCRCLo0 = bCRCLo; break; case 1: pbData1 = pData; bCRCHi1 = bCRCHi; bCRCLo1 = bCRCLo; break; case 2: pbData2 = pData; bCRCHi2 = bCRCHi; bCRCLo2 = bCRCLo; break; case 3: pbData3 = pData; bCRCHi3 = bCRCHi; bCRCLo3 = bCRCLo; break; default: ASSERT(false); } Answer(wSize+bHEADER,SER_HEADER); }
void BftpMaker::addAnswer() { qsrand(QTime::currentTime().msec()); ansList.append(new AnswerEdit(Answer(tr("empty"), false), ansList.size() + qrand())); ui->answers->addWidget(ansList.last()); connect(ansList.last(), &AnswerEdit::remove, this, &BftpMaker::removeAnswer); }
/* * Return true if the answer supplied by the user to the given question * starts with 'y', false otherwise. */ boolean Answer (char *question) { char buf[MAXSTRLEN]; printf("%s\n", question); gets(buf); if (buf[0]) { return buf[0] == 'y'; } else { printf("Please provide an answer\n"); return Answer(question); } }
main () { freopen ( "p.in" , "r" , stdin ); freopen ( "p.out" , "w" , stdout ); int total; for ( scanf ( "%d" , &total ); total; total -- ) { init (); printf ( "%.2lf\n" , Answer () ); if ( total ) printf ( "\n" ); } }
int main() { int i,x,y; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { scanf("%d",&arr[i]); } printf("%d\n",Answer()); for(i=0;i<m;i++) { scanf("%d%d",&x,&y); arr[x-1]=y; printf("%d\n",Answer()); } return 0; }
abyss_bool HandleDump(TSession *r) { char z[50]; if (strcmp(r->uri,"/name")!=0) return FALSE; sprintf(z,"Server name is %s", (r->server)->name ); Answer(r,200,z); return TRUE; }
void Solve::solve(FILE *fin, FILE *fout) { #define LVTX(x) ((x)*2) #define RVTX(x) ((x)*2+1) int n, m; fscanf(fin, "%d%d", &n, &m); nVtx = n * 2 + 2; int sVtx = nVtx - 2, tVtx = nVtx - 1; for(int u = 0, t; u < n; u ++) { fscanf(fin, "%d", &t); addEdge(RVTX(u), tVtx, t); } for(int u = 0, t; u < n; u ++) { fscanf(fin, "%d", &t); addEdge(sVtx, LVTX(u), t); } while(m --) { int u, v; fscanf(fin, "%d%d", &u, &v); addEdge(LVTX(u - 1), RVTX(v - 1), FLOW_INF); } fprintf(fout, "%d\n", dinic(sVtx, tVtx)); dfs(sVtx); int nAns = 0; for(Edge *e = begin[sVtx]; e; e = e->next) if(! vis[e->vtx]) ans[nAns ++] = Answer(e->vtx / 2 + 1, -1); for(Edge *e = begin[tVtx]; e; e = e->next) if(vis[e->vtx]) ans[nAns ++] = Answer((e->vtx - 1) / 2 + 1, 1); fprintf(fout, "%d\n", nAns); for(int i = 0; i < nAns; i ++) if(ans[i].flag == 1) fprintf(fout, "%d +\n", ans[i].idx); else fprintf(fout, "%d -\n", ans[i].idx); }
static INT_PTR CMAnswer(WPARAM wParam, LPARAM lParam) { HANDLE hContact = (HANDLE) wParam; if (hContact == NULL) return -1; hContact = ConvertMetacontact(hContact); VoiceCall *call = FindVoiceCall(hContact); if (call != NULL) Answer(call); return 0; }
main () { freopen ( "p.in" , "r" , stdin ); freopen ( "p.out" , "w" , stdout ); int step = 0; while ( 1 ) { scanf ( "%d %d" , &w , &d ); if ( w == 0 && d == 0 ) break; step ++; printf ( "Sample #%d\n" , step ); Ans = 5730 * log ( double ( d ) / w / 810 ) / log ( 0.5 ); if ( Ans > 10000 ) { printf ( "The approximate age is %d years.\n" , Answer ( Ans , 1000 )); } else { printf ( "The approximate age is %d years.\n" , Answer ( Ans , 100 ) ); } printf ( "\n" ); } }
abyss_bool HandleMIMEType(TSession *r) { char *m; if (strncmp(r->uri,"/mime/",6)!=0) return FALSE; m=MIMETypeFromExt(r->uri+6); if (!m) m="(none)"; Answer(r,200,m); return TRUE; }
void Output(uint wSize) { InitPush(0); PushChar(bLogical); PushChar(0); PushChar( (wSize+7) % 0x100 ); PushChar( (wSize+7) / 0x100 ); PushChar(bQuery); MakeCRC16OutBuff(0,wSize+5); Skip(wSize); PushChar(bCRCHi); PushChar(bCRCLo); Answer(wSize+7,SER_OUTPUT_SLAVE); }
int main(int argc, char *argv[]) { int num; char input[10], *temp, hold; printf("Post-fix calculator. Please enter a number or an operation (+, -, *) " "one per line. Enter '=' to display answer\n"); while (loop) { fgets(input, 10, stdin); temp = strtok(input, " \n"); strcpy(input, temp); if (strlen(input) > 1) { num = atoi(input); Push(num); } else { hold = input[0]; if (isdigit(hold)) { num = atoi(input); Push(num); } else { if (hold == '=') Answer(); else Math(hold); } } } return 0; }
static INT_PTR VoiceState(WPARAM wParam, LPARAM lParam) { VOICE_CALL *in = (VOICE_CALL *) wParam; if (in == NULL || in->cbSize < sizeof(VOICE_CALL) || in->moduleName == NULL || in->id == NULL) return 0; // Check if the call is aready in list VoiceCall *call = FindVoiceCall(in->moduleName, in->id, !IsFinalState(in->state)); if (call == NULL) return 0; call->AppendCallerID(in->hContact, (in->flags & VOICE_UNICODE) ? WcharToTchar(in->pwszName).get() : CharToTchar(in->pszName).get(), (in->flags & VOICE_UNICODE) ? WcharToTchar(in->pwszNumber).get() : CharToTchar(in->pszNumber).get()); call->secure = (in->flags & VOICE_SECURE) != 0; if (in->state == VOICE_STATE_RINGING && call->hContact != NULL) { int aut = DBGetContactSettingWord(call->hContact, MODULE_NAME, "AutoAccept", AUTO_NOTHING); if (aut == AUTO_ACCEPT || aut == AUTO_DROP) { call->state = VOICE_STATE_RINGING; call->Notify(true, false, false, false); if (aut == AUTO_ACCEPT) Answer(call); else call->Drop(); return 0; } } if (in->state == VOICE_STATE_TALKING) HoldOtherCalls(call); call->SetState(in->state); return 0; }
boost::optional<Answer> YacProposalStorage::findRejectProof() { auto max_vote = std::max_element(block_storages_.begin(), block_storages_.end(), [](auto &left, auto &right) { return left.getNumberOfVotes() < right.getNumberOfVotes(); }) ->getNumberOfVotes(); auto all_votes = std::accumulate(block_storages_.begin(), block_storages_.end(), 0ull, [](auto &acc, auto &storage) { return acc + storage.getNumberOfVotes(); }); auto is_reject = supermajority_checker_->hasReject( max_vote, all_votes, peers_in_round_); if (is_reject) { std::vector<VoteMessage> result; result.reserve(all_votes); std::for_each(block_storages_.begin(), block_storages_.end(), [&result](auto &storage) { auto votes_from_block_storage = storage.getVotes(); std::move(votes_from_block_storage.begin(), votes_from_block_storage.end(), std::back_inserter(result)); }); return Answer(RejectMessage(std::move(result))); } return boost::none; }
void compare() { fp_in = fopen(file_input,"r"); fp_out = fopen(file_output,"r"); fp_ans = fopen(file_answer,"r"); if (fp_out == NULL) Answer(0,RLT_NOFILE); int co,ca; for (position = 0;;++position) { co = getc(fp_out); ca = getc(fp_ans); //output ended but answer not if (feof(fp_out)) { while (!feof(fp_ans)) { if (ca != '\n' && ca !=' ') Answer(0.0,RLT_SHORTER); ca = getc(fp_ans); } return Answer(1.0,RLT_CORRECT); } //answer ended but output not if (feof(fp_ans)) { while (!feof(fp_out)) { if (co != '\n' && co !=' ') Answer(0.0,RLT_LONGER); co = getc(fp_out); } return Answer(1.0,RLT_CORRECT); } if (co != ca) return Answer(0.0,RLT_MISMATCH); } }
Answer Solver::Solve(Problem &prob) { auto statuses = tbb::concurrent_vector<Answer>(); auto nextStatuses = tbb::concurrent_vector<Answer>(); auto hashTable = tbb::concurrent_unordered_set<Answer, std::hash<Answer>>(); int maxZk = 0; int minUsed = 256; statuses.push_back(std::move(Answer(prob))); while (_bestFirst || statuses.front()._stoneCount != statuses.front()._places.size()) { if (_bestFirst) { // 最良優先ビームサーチ // ハッシュテーブルが大きすぎる場合の処理 if (hashTable.size() > _maxQueueSize) { tbb::concurrent_vector<Answer> tmp; tbb::concurrent_unordered_set<Answer, std::hash<Answer>> newHashTable; for (const auto & status : hashTable) tmp.push_back(status); tbb::parallel_sort(ALL(tmp), std::greater<Answer>()); for (int i = 0; i < _maxQueueSize; i++) newHashTable.insert(tmp[i]); hashTable = std::move(newHashTable); } } else { // 幅優先ビームサーチ hashTable = tbb::concurrent_unordered_set<Answer, std::hash<Answer>>(); } if (_beam < statuses.size()) { tbb::parallel_sort(ALL(statuses), std::greater<Answer>()); tbb::concurrent_vector<Answer> tmp; tmp.resize(_beam); for (int i = 0; i < _beam; i++) tmp[i] = statuses[i]; statuses = std::move(tmp); } // 並列処理! tbb::parallel_for_each(ALL(statuses), [&](Answer ¤t) { auto next = current; if (statuses.front()._stoneCount != statuses.front()._places.size()) { if (current.first()) { for (int i = 0; i <= 1; i++) // up { for (int j = 0; j < 4; j++) // dir { for (int y = -7; y < 32; y++) { for (int x = -7; x < 32; x++) { if (next.applyPlacement(x, y, (bool)i, (Direction)j)) { auto it = hashTable.find(next); if (it == hashTable.end()) { hashTable.insert(next); } else { if (*it < next) { *it = next; } } next = current; } } } } } } else { auto &stone = current._stones[current._places.size()]; for (int i = 0; i <= 1; i++) // up { for (int j = 0; j < 4; j++) // dir { bool alreadyPlaced[39][39]; memset(alreadyPlaced, 0, sizeof(alreadyPlaced)); for (auto stonePos : stone.stonePos((bool)i, (Direction)j)) for (auto neighborPos : current._neighbors) alreadyPlaced[neighborPos._y - stonePos._y + 1 + 7][neighborPos._x - stonePos._x + 1 + 7] = true; for (int y = 0; y < 39; y++) { for (int x = 0; x < 39; x++) { if (alreadyPlaced[y][x]) { if (next.applyPlacement(x - 7, y - 7, (bool)i, (Direction)j)) { auto it = hashTable.find(next); if (it == hashTable.end()) { hashTable.insert(next); } else { if (*it < next) *it = next; } next = current; } } } } } } } current.skipStone(); nextStatuses.push_back(current); } }); statuses = std::move(nextStatuses); for (auto status : hashTable) { if (_bestFirst) { if (status._stoneCount == status._places.size()) { if (maxZk < status.zk()) { maxZk = status.zk(); minUsed = status.used(); // int value = (1024 - status.zk()) * 257 + status.used(); // std::cout << value << std::endl; // std::cout << status.getAnswer(); } else if (maxZk == status.zk() && minUsed > status.used()) { minUsed = status.used(); // int value = (1024 - status.zk()) * 257 + status.used(); // std::cout << value << std::endl; // std::cout << status.getAnswer(); } } } statuses.push_back(std::move(status)); } } Answer result; if (!_bestFirst) { int maxZk = 0; int minUsed = 256; for (const auto & status : statuses) { if (maxZk < status.zk()) { maxZk = status.zk(); minUsed = status.used(); result = status; } else if (maxZk == status.zk() && minUsed > status.used()) { minUsed = status.used(); result = status; } } // int value = (1024 - result.zk()) * 257 + result.used(); // std::cout << value << std::endl; // std::cout << result.getAnswer(); } return result; }
static BOOL CALLBACK DlgProcNewCall(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: { VoiceCall *call = (VoiceCall *) lParam; TranslateDialogDefault(hwndDlg); TCHAR text[1024]; VoiceCall *currentCall = GetTalkingCall(); if (currentCall == NULL) { mir_sntprintf(text, MAX_REGS(text), TranslateT("%s wants to start a voice call with you. What you want to do?"), call->displayName); } else if (currentCall->CanHold()) { mir_sntprintf(text, MAX_REGS(text), TranslateT("%s wants to start a voice call with you. What you want to do?\n\nIf you answer the call, the current call will be put on hold."), call->displayName); } else { mir_sntprintf(text, MAX_REGS(text), TranslateT("%s wants to start a voice call with you. What you want to do?\n\nIf you answer the call, the current call will be dropped."), call->displayName); } SendMessage(GetDlgItem(hwndDlg, IDC_TEXT), WM_SETTEXT, 0, (LPARAM) text); HICON hIcon = IcoLib_LoadIcon(stateIcons[VOICE_STATE_RINGING]); SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon); IcoLib_ReleaseIcon(hIcon); if (call->hContact == NULL) ShowWindow(GetDlgItem(hwndDlg, IDC_AUTO), SW_HIDE); SetWindowLong(hwndDlg, GWL_USERDATA, (LONG) call); return TRUE; } case WM_COMMAND: { switch(wParam) { case ID_ANSWER: { VoiceCall *call = (VoiceCall *) GetWindowLong(hwndDlg, GWL_USERDATA); if (call->hContact != NULL && IsDlgButtonChecked(hwndDlg, IDC_AUTO)) DBWriteContactSettingWord(call->hContact, MODULE_NAME, "AutoAccept", AUTO_ACCEPT); Answer(call); DestroyWindow(hwndDlg); break; } case ID_DROP: { VoiceCall *call = (VoiceCall *) GetWindowLong(hwndDlg, GWL_USERDATA); if (call->hContact != NULL && IsDlgButtonChecked(hwndDlg, IDC_AUTO)) DBWriteContactSettingWord(call->hContact, MODULE_NAME, "AutoAccept", AUTO_DROP); call->Drop(); DestroyWindow(hwndDlg); break; } } break; } case WM_CLOSE: { VoiceCall *call = (VoiceCall *) GetWindowLong(hwndDlg, GWL_USERDATA); call->Notify(false, false, false, true); DestroyWindow(hwndDlg); break; } case WM_DESTROY: { VoiceCall *call = (VoiceCall *) GetWindowLong(hwndDlg, GWL_USERDATA); call->SetNewCallHWND(NULL); break; } } return FALSE; }
int main() { int a = Answer(); return a; }
main () { while ( scanf ( "%d" , &N ) , N ) printf ( "%d\n" , Answer () ); }
void main(void) { int p; // // set network characteristics // doomcom.ticdup = 1; doomcom.extratics = 0; doomcom.numnodes = 2; doomcom.numplayers = 2; doomcom.drone = 0; printf("\n" "---------------------------------\n" #ifdef DOOM2 STR_DOOMSERIAL"\n" #else "DOOM SERIAL DEVICE DRIVER v1.4\n" #endif "---------------------------------\n"); myargc = _argc; myargv = _argv; FindResponseFile(); // // allow override of automatic player ordering to allow a slower computer // to be set as player 1 allways // // // establish communications // baudbits = 0x08; // default to 9600 if not specified on cmd line // or in modem.cfg if (CheckParm ("-dial") || CheckParm ("-answer") ) ReadModemCfg (); // may set baudbits // // allow command-line override of modem.cfg baud rate // if (CheckParm ("-9600")) baudbits = 0x0c; else if (CheckParm ("-14400")) baudbits = 0x08; else if (CheckParm ("-19200")) baudbits = 0x06; else if (CheckParm ("-38400")) baudbits = 0x03; else if (CheckParm ("-57600")) baudbits = 0x02; else if (CheckParm ("-115200")) baudbits = 0x01; InitPort (); if (CheckParm ("-dial")) Dial (); else if (CheckParm ("-answer")) Answer (); Connect (); // // launch DOOM // LaunchDOOM (); Error (NULL); }
void HttpOutput::Answer(const std::string& str) { Answer(str.size() == 0 ? NULL : str.c_str(), str.size()); }
Answer(char aName[200],int aLength) { Answer(); strcpy(name,aName); length=aLength; }
void cColorDialog::Ask() { m_ColorCode = ShowModal(); Answer(); }
void OutgoingRoap::OnCallConnected(char* sdp) { if (strcmp(sdp,"") != 0) Answer("callerSessionId", "calleeSessionId", "seq", sdp); }