int clone_ident::operator&(const clone_ident &c) { char *p, *q; if(isPrefix(*user->ident)) p = user->ident + 1; else p = user->ident; if(isPrefix(*c.user->ident)) q = c.user->ident + 1; else q = c.user->ident; return !strcmp(p, q); }
void recursiveSolve(TreeNode *lexTree, WBCell *cell, int solutionLen, char *solutionSoFar) { // base case - if solution is of correct length and is an actual word, then print it if(strlen(solutionSoFar) == solutionLen){ if(isSolution(lexTree, solutionSoFar)){ printf("%s\n", solutionSoFar); } // else, word isn't long enough yet. Try expanding in all directions } else { int newLetterIndex = strlen(solutionSoFar); for(int i = 0; i < NUM_ADJACENT_CELLS; i++){ WBCell *nextCellPtr = cell->adjacentCells[i]; if(nextCellPtr!=NULL && !nextCellPtr->visited){ solutionSoFar[newLetterIndex]=(*nextCellPtr).value; // if new direction is a valid prefix, mark current cell as visited, // and recurse on next cell with updated solution if(isPrefix(lexTree, solutionSoFar)){ cell->visited = 1; recursiveSolve(lexTree, nextCellPtr, solutionLen, solutionSoFar); } // unwind after returning from recursion cell->visited = 0; solutionSoFar[newLetterIndex] = '\0'; } } } }
BOOL TSHPath::IsPrefix(LPCTSTR pszPrefix, LPCTSTR pszPath) { static TModuleProc2<BOOL,LPCTSTR,LPCTSTR> isPrefix(GetModule(), IsPrefixStr); return isPrefix(pszPrefix, pszPath); }
int main(void) { char string1[500], string2[500]; char *ptr1 = NULL; char *ptr2 = NULL; int result; int i = 0, size1 = -1, size2 = -1;//size is the size of the first and second substring printf("Please type in the first string:\n"); ptr1 = fgets(string1,100,stdin); while (*(ptr1 + i) != 0)//finds the size of the first array { i++; size1++; } printf("Please type in the second string:\n"); ptr2 = fgets(string2,100,stdin); i=0; while (*(ptr2 + i) != 0)//finds the size of the second array { i++; size2+=1; } //printf("ptr1 = %sptr2 = %s",ptr1,ptr2); result = isSubString(ptr1, ptr2, size1); if (result == 1) printf("\nThe second string is a substring of the first string\n\n"); else if (result == 0) printf("The second string is a NOT substring of the first string\n\n"); /*not a substring*/ result = isPrefix(ptr1, ptr2, size1); if (result == 1) printf("The second string is a prefix of the first string\n\n"); else if (result == 0) printf("The second string is NOT a prefix of the first string\n\n"); result = isPostFix(ptr1, ptr2, size1); if (result == 1) printf("The second string is a postfix of the first string\n\n"); else printf("The second string NOT is a postfix of the first string\n\n"); result =isInString(ptr1, ptr2, size1, size2); if (result == 1) printf("The second string is the same as the first string.\n\n"); else if (result == 0) printf("The second string is NOT the same as the first string.\n\n"); return 0; }
bool TeamLeaguePlugin::OnQTell(ServerOuputQTellType soq, const std::string& fullline) { if (soq == SOQ_Generic && isPrefix(CONFIG_BOT_QTELL_IDENTIFIER, fullline)) { Status_t status = dataset_.ProcessDataChunk(fullline); if (status == STATUS_OK_GAME_UPDATE_COMPLETED || status == STATUS_OK_EMPTY_DATASET) { // TODO do something special on empty dataset UpdateTabset(); } return false; } return true; }
void findWord(char* currentWord, const char board[4][4], int position, struct ListNode** HEAD) { int i, j, index; int row = position / 4; int col = position % 4; char* newWord = malloc(sizeof(char) * 33); if (newWord == NULL) { printf("Could not allocate enough memory. Returning.\n"); return; } memset(newWord, 0, 32); char adjacent; strcpy(newWord, currentWord); index = strlen(newWord); for (i = row-1; i <= row+1; i++) { for (j = col-1; j <= col+1; j++) { adjacent = getAdjacentChar(i, j, board); if (adjacent != 0 && !containsChar(adjacent, newWord)) { newWord[index] = board[i][j]; if (isWord(newWord)) { struct ListNode* newNode = malloc(sizeof(struct ListNode)); newNode->word = malloc(strlen(newWord) + 1); if (newNode == NULL || newNode->word == NULL) { printf("Could not allocate enough memory. Returning.\n"); return; } strcpy(newNode->word, newWord); newNode->next = *HEAD; *HEAD = newNode; ++index; } if (isPrefix(newWord)) { findWord(newWord, board, i*4+j, HEAD); } } } } free(newWord); }
bool isGood(int l){ int lastInd = 0, cnt = 0; for (int i = 1; i <= n; i++) { if(strlen(words[i]) <= l) { if (!isPrefix(words[lastInd], words[i])) { cnt++; } lastInd = i; } } return cnt >= k; }
/** * Makes the jump table based on the scan offset which mismatch occurs. */ void BMStringMatch::makeOffsetTable(std::string& needle) { offsetTable.resize(needle.length(), 0); int lastPrefixPosition = needle.length(); for (int i = needle.length() - 1; i >= 0; --i) { if (isPrefix(needle, i + 1)) { lastPrefixPosition = i + 1; } offsetTable[needle.length() - 1 - i] = lastPrefixPosition - i + needle.length() - 1; } for (int i = 0; i < (int)needle.length() - 1; ++i) { int slen = suffixLength(needle, i); offsetTable[slen] = needle.length() - 1 - i + slen; } }
bool EntryEdict::matchesWordType( const DictQuery &query ) const { if( ! query.isEmpty() ) { if( query.getMatchWordType() == DictQuery::Verb && isVerb() ) { return true; } if( query.getMatchWordType() == DictQuery::Noun && isNoun() ) { return true; } if( query.getMatchWordType() == DictQuery::Adjective && isAdjective() ) { return true; } if( query.getMatchWordType() == DictQuery::Adverb && isAdverb() ) { return true; } if( query.getMatchWordType() == DictQuery::Expression && isExpression() ) { return true; } if( query.getMatchWordType() == DictQuery::Prefix && isPrefix() ) { return true; } if( query.getMatchWordType() == DictQuery::Suffix && isSuffix() ) { return true; } if( query.getMatchWordType() == DictQuery::Any ) { return true; } } return false; }
/* Print "COMPLETION: " followed by the TypedText chunk of the completion * string to fp, that's the text that a user would be expected to type to get * this code-completion result. TypedText is the keyword for the client program * (emacs script in this case) to filter completion results. * * Only prints a completion if it matches the given prefix. * * This function returns the number of matching completion chunks on success, or it * would return an -1 if no matching TypedText chunk was found. */ static int completion_printCompletionHeadTerm( CXCompletionString completion_string, FILE *fp, char *prefix) { int i_chunk = 0; int n_chunks = clang_getNumCompletionChunks(completion_string); CXString ac_string; /* inspect all chunks only to find the TypedText chunk */ for ( ; i_chunk < n_chunks; i_chunk++) { if (clang_getCompletionChunkKind(completion_string, i_chunk) == CXCompletionChunk_TypedText) { /* We got it, dump it to fp if it matches the prefix */ ac_string = clang_getCompletionChunkText(completion_string, i_chunk); char *cstring = (char *)clang_getCString(ac_string); if (isPrefix(prefix, cstring) > 0) { return -1; } fprintf(fp, "COMPLETION: %s", cstring); clang_disposeString(ac_string); return n_chunks; /* care package on the way */ } } return -1; /* We haven't found TypedText chunk in completion_string */ }
int isSerialPortDev(char *s) { return isPrefix("ttyusb", s); }
int main(int argc, char **argv) { ros::init(argc, argv, std::string("behavior")); kobuki_msgs::Sound sound; tf::TransformListener tfL; ros::NodeHandle n; Pid pid; ros::Subscriber robotposesub = n.subscribe("/MCLRobotica_pos", 1000, &poseCB); ros::Publisher cmdpub = n.advertise<geometry_msgs::Twist>("mobile_base/commands/velocity", 1000); ros::Publisher sonido = n.advertise<kobuki_msgs::Sound>("mobile_base/commands/sound",1); ros::Subscriber lost_sub = n.subscribe("/MCLRobotica_lost", 1000, &lostCB); ros::Subscriber notlost_sub = n.subscribe("/MCLRobotica_notlost", 1000, ¬lostCB); // ros::Publisher chatter_pub = n.advertise<geometry_msgs::Twist>("mobile_base/commands/velocity", 1000); ros::Rate loop_rate(10); int count = 0; int state = SEARCH; std::string target; std::string blacklist[NUMBOLAS]; int bolas = 0; lastPose.pose.position.z = -1.0; geometry_msgs::Twist cmd; cmd.linear.y = 0.0; cmd.linear.z = 0.0; cmd.angular.x = 0.0; cmd.angular.y = 0.0; cmd.angular.z = 0.0; cmd.linear.x = 0.0; float angle2goal; while (ros::ok()) { if(bolas == 3) break; switch(state){ case SEARCH: { target = "A"; std::vector<std::string> frameList; tfL.getFrameStrings(frameList); std::vector<std::string>::iterator it; float dmin = 99.9; for (it = frameList.begin(); it != frameList.end(); ++it) { std::string frame = *it; tf::StampedTransform BL2B; try { tfL.lookupTransform("base_link", frame, ros::Time::now(), BL2B); if (isPrefix("ball_", frame) && !isBlacklisted(frame, blacklist, bolas)) { int d = getDistanceTo(frame); if(dmin > d){ dmin = d; target = frame; } state = GOTOBALL; } } catch (tf::TransformException & ex) { ;//ROS_WARN("%s", ex.what()); } } if(target.compare("A")==0) std::cout<<"NADA"<<std::endl; else std::cout<<"TARGET = "<<target<<std::endl; cmd.linear.x = 0.2; if(cmd.angular.z <= 0.4) cmd.angular.z = cmd.angular.z + 0.01; break; } case GOTOBALL: { tf::StampedTransform BL2B; try{ tfL.lookupTransform("base_link", target, ros::Time::now() - ros::Duration(1.0), BL2B); }catch(tf::TransformException & ex) { ROS_WARN("LA HE PERDIDO: %s", ex.what()); state = SEARCH; cmd.angular.z = 0.0; break; } float ro; ro = sqrt((BL2B.getOrigin().x())*(BL2B.getOrigin().x()) + (BL2B.getOrigin().y())*(BL2B.getOrigin().y())); double roll, pitch, yaw; float v,w, usoPid; Pid velDeGiro; float theta; std::cout<<"pelota "<<target<<" ro = "<<ro<<std::endl; if(ro < 0.7){ w = v = 0.0; sound.value=kobuki_msgs::Sound::CLEANINGSTART; sonido.publish(sound); //AQUI SE REPRODUCE UN SONIDO state = GOTOBIN; cmd.linear.x = v; cmd.angular.z = w; }else{ theta = normalizePi(atan2(BL2B.getOrigin().y(), BL2B.getOrigin().x())); std::cerr<<"theta: "<<fabs(theta)<<std::endl; usoPid=velDeGiro.OperarMiPid(theta); cmd.angular.z = usoPid; if(fabs(theta) > 0.1){ v = 0.1; cmd.linear.x = v; }else{ v = 0.2;//AQUI HABRIA QUE HACER UN VFF SENCILLO QUE SOLO TENGA EN CUENTA LA DISTANCIA HASTA LA PELOTA cmd.linear.x = v; } } break; } case GOTOBIN: { if(lost){ std::cout<<"LAST POSE: "<<lastPose.pose.position.z<<std::endl; if(lastPose.pose.position.z == -1.0){ if(count % 200 < 160){ std::cout<<"giro para encontrarme"<<std::endl; cmd.angular.z = 0.2; cmd.linear.x = 0.0; }else{ std::cout<<"Avanzo para encontrarme"<<std::endl; cmd.linear.x = 0.1; cmd.angular.z = 0.0; } }else{ tf::StampedTransform W2BIn; try{ tfL.lookupTransform("world", "bin", ros::Time::now() - ros::Duration(1.0), W2BIn); }catch(tf::TransformException & ex) { ROS_WARN("%s", ex.what()); break; } double roll, pitch, yaw; tf::Quaternion q(pose.pose.orientation.x, pose.pose.orientation.y, pose.pose.orientation.z, pose.pose.orientation.w); tf::Matrix3x3(q).getRPY(roll, pitch, yaw); angle2goal2 = normalizePi(atan2(W2BIn.getOrigin().y() - lastPose.pose.position.y, W2BIn.getOrigin().x() -lastPose.pose.position.x) - yaw); ETA = ros::Time::now() + ros::Duration(fabs(angle2goal2*23)/(2*M_PI)); state = GIRANDO; diffpose2 = sqrt((lastPose.pose.position.x-W2BIn.getOrigin().x())*(lastPose.pose.position.x-W2BIn.getOrigin().x()) + (lastPose.pose.position.y-W2BIn.getOrigin().y())*(lastPose.pose.position.y-W2BIn.getOrigin().y())); } break; }else{ tf::StampedTransform W2BIn; try{ tfL.lookupTransform("world", "bin", ros::Time::now() - ros::Duration(1.0), W2BIn); }catch(tf::TransformException & ex) { ROS_WARN("%s", ex.what()); break; } float diffpose; lastPose = pose; diffpose = sqrt((pose.pose.position.x-W2BIn.getOrigin().x())*(pose.pose.position.x-W2BIn.getOrigin().x()) + (pose.pose.position.y-W2BIn.getOrigin().y())*(pose.pose.position.y-W2BIn.getOrigin().y())); double roll, pitch, yaw; tf::Quaternion q(pose.pose.orientation.x, pose.pose.orientation.y, pose.pose.orientation.z, pose.pose.orientation.w); tf::Matrix3x3(q).getRPY(roll, pitch, yaw); float v,w, usoPid; Pid velDeGiro; if(diffpose < 0.1){ //std::cerr<<"diffpose: "<<diffpose<<std::endl; w = v = 0.0; sound.value=kobuki_msgs::Sound::CLEANINGSTART; sonido.publish(sound); //AQUI SE REPRODUCE UN SONIDO Y SE ELIMINA LA PELOTA blacklist[bolas] = target; bolas++; state = SEARCH; cmd.angular.z = 0.0; cmd.linear.x = 0.0; lastPose.pose.position.z = -1; }else{ angle2goal = normalizePi(atan2(W2BIn.getOrigin().y() - pose.pose.position.y, W2BIn.getOrigin().x() -pose.pose.position.x) - yaw); //std::cerr<<"angle2goal: "<<fabs(angle2goal)<<std::endl; usoPid=velDeGiro.OperarMiPid(angle2goal); cmd.angular.z = usoPid; if(fabs(angle2goal) > 0.2){ v = 0.0; cmd.linear.x = v; }else{ v = 0.3;//AQUI HABRIA QUE HACER UN VFF SENCILLO QUE SOLO TENGA EN CUENTA LA DISTANCIA HASTA BIn cmd.linear.x = v; } } break; //si no funciona según lo esperado, este break lo tenía puesto antes encima del case GIRANDO, pero creo que aqui //hace mejor su función } } case GIRANDO: { cmd.angular.z = 0.0; cmd.angular.y = 0.0; cmd.angular.x = 0.0; cmd.linear.x = 0.0; cmd.linear.y = 0.0; cmd.linear.z = 0.0; if(ros::Time::now() < ETA){ if(angle2goal2>=0){ std::cout<<"entro a girar izquierda"<<std::endl; cmd.angular.z = 0.3; }else{ std::cout<<"entro a girar derecha"<<std::endl; cmd.angular.z = -0.3; } }else{ state = AVANZAR_ESPARTANOS; ETA2 = ros::Time::now() + ros::Duration(diffpose2/VELOCIDAD_LINEAL); } cmdpub.publish(cmd); break; } case AVANZAR_ESPARTANOS: { cmd.angular.z = 0.0; cmd.angular.y = 0.0; cmd.angular.x = 0.0; cmd.linear.x = 0.0; cmd.linear.y = 0.0; cmd.linear.z = 0.0; if(ros::Time::now() < ETA2){ std::cout<<"entro a avanzar"<<std::endl; cmd.linear.x = 0.3; }else{ sound.value=6;//kobuki_msgs::Sound::CLEANINGSTART; sonido.publish(sound); blacklist[bolas] = target; bolas++; state = VE_HACIA_ATRAS; //voy a retroceder el mismo tiempo y a la misma velocidad de lo que habia avanzado Tiempo_Hacia_Atras = ros::Time::now() + ros::Duration(diffpose2/VELOCIDAD_LINEAL); } //lastPose.pose.position.z = -1; cmdpub.publish(cmd); break; } case VE_HACIA_ATRAS: { cmd.angular.z = 0.0; cmd.angular.y = 0.0; cmd.angular.x = 0.0; cmd.linear.x = 0.0; cmd.linear.y = 0.0; cmd.linear.z = 0.0; if(ros::Time::now() < Tiempo_Hacia_Atras){ std::cout<<"voy a dar marcha atras"<<std::endl; cmd.linear.x = -0.3; }else{ state = SEARCH; } lastPose.pose.position.z = -1; cmdpub.publish(cmd); break; } default: std::cout<<"WHAT THE F**K"<<std::endl; } cmdpub.publish(cmd); ros::spinOnce(); loop_rate.sleep(); ++count; } return 0; }
bool Path::isRootdir(const std::string& s) { // redundant test on unix, but second test covers windows return isPrefix(s); }
bool isInfix(QString p) { if (!isPostfix(p) && !isPrefix(p)) return true; return false; }