bool Troop::swap(Pet* pet1, Pet* pet2) { if (!pet1 || !pet2) { return false; } CCPoint tempPosition1 = pet1->getPosition(); CCPoint tempPosition2 = pet2->getPosition(); int index1 = pet1->getIndex(); int index2 = pet2->getIndex(); pet1->lock(); pet2->lock(); pet1->runAction(CCMoveTo::create(0.25, tempPosition2)); pet2->runAction(CCMoveTo::create(0.25, tempPosition1)); if (pet1->getType()->isEqual(pet2->getType()) || (!tryPosition(index1, pet2) && !tryPosition(index2, pet1))) { pet1->runAction(CCSequence::create(CCDelayTime::create(0.25), CCMoveTo::create(0.25, tempPosition1), CCCallFunc::create(pet1, callfunc_selector(Pet::unlock)), NULL)); pet2->runAction(CCSequence::create(CCDelayTime::create(0.25), CCMoveTo::create(0.25, tempPosition2), CCCallFunc::create(pet2, callfunc_selector(Pet::unlock)), NULL)); } else { kickOut(pet1); kickOut(pet2); addPetAt(pet1, index2, 0.5); addPetAt(pet2, index1, 0.5); } return false; }
static void placeDTIcon(DTIconRec *dticon) { Dimension width; XmString labelstr; String icon_pos; if (x0 == -1) { /* Seems to be necessary at least under HP-UX: */ icon_pos = XtNewString(resources.icon_pos); sscanf(icon_pos, "%d%d", &x0, &y0); XTFREE(icon_pos); if (x0 < 0) x0 += winInfo.rootWidth - DTICONWIDTH; if (y0 < 0) y0 += winInfo.rootHeight - DTICONHEIGHT; } dticon->x = x0; dticon->y = y0; dticon->width = dticon->app.icon_pm.width; dticon->height = dticon->app.icon_pm.height; labelstr = XmStringCreateLocalized(dticon->app.name); width = XmStringWidth((XmFontList) resources.icon_font, labelstr) + 2; dticon->height += XmStringWidth((XmFontList) resources.icon_font, labelstr) + 4; if (width > dticon->width) dticon->width = width; dticon->height += 2 * MARGIN; dticon->width += 2 * MARGIN; while (!tryPosition(dticon)); dticon->x += MARGIN; dticon->y += MARGIN; }
int main(){ while(!dict.eof()){ std::string word; dict>>word; dictionary.insert(word); } in.clear(); in>>number; std::string word=number; if(!tryPosition(word,0)) out<<"NONE"<<std::endl; return 0; }
bool tryPosition(std::string &word,int position){ if(position==number.length()){ #ifdef DEBUG out<<">\t"<<word<<std::endl; #endif if(dictionary.find(word)!=dictionary.end()){ out<<word<<std::endl; return true; } return false; } bool found=false; for(int i=0;i<3;i++){ word[position]=MAP_TABLE[number[position]-'2'][i]; if(tryPosition(word,position+1)) found=true; } return found; }