ScoreTreeNode findScore(int score, ScoreTreeNode tree) { if(tree == NULL) return NULL; if(score < tree->score) { return findScore(score, tree->left); } else if(score > tree->score) { return findScore(score, tree->right); } return tree; }
void Top100::calculate(MiniUser *u) { if (!u) return; Cmd::MiniGameScore s = u->getGameScore(); /* for (top_iter i=top100.begin(); i!=top100.end(); i++) if (i->id==u->id) { top100.erase(i); return; } */ top_iter ti = std::find_if(top100.begin(),top100.end(),findID(u->id)); if (ti!=top100.end()) top100.erase(ti); if (top100.size()>=120 && s<top100.rbegin()->score) return; //top_iter i=top100.begin(); //for (; i!=top100.end() && i->score>s; i++); top_iter i = std::find_if(top100.begin(),top100.end(),findScore(s)); Cmd::MiniUserData d; u->full_MiniUserData(0,d); top100.insert(i,d); if (top100.size()>120) top100.erase(--top100.end()); //for (top_iter i=top100.begin(); i!=top100.end(); i++) // Xlogger->debug("Top100\t%s(%u)\tscore=%d",i->name,i->id,i->score.score); }
int main() { int t,i,score; char str[10000]; scanf("%d",&t); while(t--) { scanf(" %[^\n]s",str); score=0; for(i=0;str[i];i++) { if(str[i]!=' ') { score=findScore(score,str[i]); if(score>21) { printf("Bust "); break; } } } if(!str[i]) printf("%d ",score); } return 0; }
// returns 1 on adding item, 0 on successful update of item, -1 on error int update(int itemId, int score) { int rval = 0; int newscore = score; ItemTreeNode itnode = findItem(itemId, item_root); if(itnode == NULL) { rval = 1; itnode = createItemTreeNode(); if(itnode == NULL) return -1; itnode->item = createItemNode(itemId); if(itnode->item == NULL) return -1; itnode->score = 0; item_root = addItemTreeNode(item_root, itnode); } ScoreTreeNode snode; if(itnode->score > 0) { snode = findScore(itnode->score, score_root); newscore = score + itnode->score; //printf("moving itemid %d to score %d from score %d\n", itnode->item->itemId, newscore, snode->score); int populated = removeItemNode(snode, itnode->item); if(!populated) { score_root = deleteScoreTreeNode(score_root, snode); } itnode->score = 0; } snode = findScore(newscore, score_root); if(snode == NULL) { snode = createScoreTreeNode(newscore); if(snode == NULL) return -1; score_root = addScoreTreeNode(score_root, snode); } addItemNode(snode, itnode->item); itnode->score = snode->score; app_stats.updates += 1; return rval; }
// // INStatsManager::recordStats // // Add stats for a particular level. // void INStatsManager::recordStats(const wbstartstruct_t *wbstats) { qstring levelkey; int scores[INSTAT_NUMTYPES]; int maxscores[INSTAT_NUMTYPES]; const wbplayerstruct_t *playerData = &wbstats->plyr[wbstats->pnum]; getLevelKey(levelkey); // really shouldn't happen if(levelkey == "") return; // not playing?? if(!playerData->in) return; // cheated? if(players[wbstats->pnum].cheats & CF_CHEATED) return; // demo? if(demoplayback) return; // copy data from wbstats/playerData to scores array scores[INSTAT_KILLS ] = playerData->skills; scores[INSTAT_ITEMS ] = playerData->sitems; scores[INSTAT_SECRETS] = playerData->ssecret; scores[INSTAT_TIME ] = playerData->stime; scores[INSTAT_FRAGS ] = players[wbstats->pnum].totalfrags; // Setup the maxscores array too maxscores[INSTAT_KILLS ] = wbstats->maxkills; maxscores[INSTAT_ITEMS ] = wbstats->maxitems; maxscores[INSTAT_SECRETS] = wbstats->maxsecret; maxscores[INSTAT_TIME ] = wbstats->partime; // Actually a minimum, of sorts. maxscores[INSTAT_FRAGS ] = -1; // There's no max for frags. for(int i = 0; i < INSTAT_NUMTYPES; i++) { in_stat_t *instat; if((instat = findScore(levelkey, i))) { // If we're not playing on the same or a better skill level, this // score can't replace the old one. if(gameskill < instat->skill) continue; // * For most categories, a higher score wins. Time is an exception. // * A tie wins if it is achieved on a higher skill level. if((gameskill > instat->skill && scores[i] == instat->value) || (i == INSTAT_TIME ? scores[i] < instat->value : scores[i] > instat->value)) { // This player has the new high score! instat->skill = gameskill; instat->value = scores[i]; instat->maxValue = maxscores[i]; E_ReplaceString(instat->playername, estrdup(players[wbstats->pnum].name)); } } else addScore(levelkey.constPtr(), scores[i], maxscores[i], i, wbstats->pnum); } }