bool isPalindrome(char * s) { if (s == NULL) return true; char * ps = s; while (*ps) if (*ps>='A' && *ps<='Z') *ps++ += 'a' - 'A'; else ++ ps; char * ss = s + strlen(s) - 1; while (ss >= s) { while (!isAlphanumeric(*ss) && ss>=s) -- ss; while (!isAlphanumeric(*s) && *s!='\0') ++ s; if (ss >= s) // Note 0: The comparison below is based on this condition. if (*s != *ss) return false; -- ss; ++ s; } return true; }
int findNextWordFromIndex(const UChar* chars, int len, int position, bool forward) { TextBreakIterator* it = wordBreakIterator(chars, len); if (forward) { position = it->following(position); while (position != TextBreakDone) { // We stop searching when the character preceeding the break // is alphanumeric. if (position < len && isAlphanumeric(chars[position - 1])) return position; position = it->following(position); } return len; } else { position = it->preceding(position); while (position != TextBreakDone) { // We stop searching when the character following the break // is alphanumeric. if (position > 0 && isAlphanumeric(chars[position])) return position; position = it->preceding(position); } return 0; } }
int isPalindrome(char* s) { int len = 0; char* p = s; while (*p++) { if (s[len] >= 'A' && s[len] <= 'Z') { s[len] += ('a' - 'A'); } ++len; } int i=0, j=len-1; while(i<j) { while ( i<j && i< len && !isAlphanumeric(s[i])) { ++i; } while ( j>i && j>=0 && !isAlphanumeric(s[j])) { --j; } if (i<j && s[i] != s[j]) { return 0; } ++i; --j; } return 1; }
bool isPalindrome(string s) { int len = s.length(); if(len<=1)return true; for(int i=0,j=len-1;i<j;i++,j--){ while(i<j && !isAlphanumeric(s[i]))i++; while(i<j && !isAlphanumeric(s[j]))j--; if(i>j)return false; if(!equal(s[i],s[j]))return false; } return true; }
TokenInfo getNextToken() { consumeWhitespace(); TokenInfo Result; Result.Range.Start = currentLocation(); if (Code.empty()) { Result.Kind = TokenInfo::TK_Eof; Result.Text = ""; return Result; } switch (Code[0]) { case ',': Result.Kind = TokenInfo::TK_Comma; Result.Text = Code.substr(0, 1); Code = Code.drop_front(); break; case '(': Result.Kind = TokenInfo::TK_OpenParen; Result.Text = Code.substr(0, 1); Code = Code.drop_front(); break; case ')': Result.Kind = TokenInfo::TK_CloseParen; Result.Text = Code.substr(0, 1); Code = Code.drop_front(); break; case '"': case '\'': // Parse a string literal. consumeStringLiteral(&Result); break; default: if (isAlphanumeric(Code[0])) { // Parse an identifier size_t TokenLength = 1; while (TokenLength < Code.size() && isAlphanumeric(Code[TokenLength])) ++TokenLength; Result.Kind = TokenInfo::TK_Ident; Result.Text = Code.substr(0, TokenLength); Code = Code.drop_front(TokenLength); } else { Result.Kind = TokenInfo::TK_InvalidChar; Result.Text = Code.substr(0, 1); Code = Code.drop_front(1); } break; } Result.Range.End = currentLocation(); return Result; }
bool Ex125::isPalindrome(string s) { int i = 0, j = s.length()-1; while(i < j) { if(!isAlphanumeric(s[i])) i++; else if(!isAlphanumeric(s[j])) j--; else if(s[i++] != s[j--]) return false; } return true; }
bool isPalindrome(string s) { int length = (int)s.length(); int i = 0, j = length - 1; while (i < j) { while (i < length && !isAlphanumeric(s[i])) ++i; if (i >= length) return true; while (j >= 0 && !isAlphanumeric(s[j])) --j; if (j < 0) return true; if (toLowerCase(s[i]) != toLowerCase(s[j])) return false; ++i, --j; } return true; }
bool isPalindrome(string s) { if (s.empty()) return true; int left = 0; int right = s.size()-1; while (right > left) { while(!isAlphanumeric(s[left]) && left < s.size()) left ++; while(!isAlphanumeric(s[right]) && 0 <= right) right --; if (s[left] != s[right] && tolower(s[left]) != tolower(s[right])) return false; left ++; right --; } return true; }
void ViewPrivate::selectWordAround(int r, int c) { BBS::Cell *cell = terminal->cellsAtRow(r); while (c >= 0) { if (isAlphanumeric(cell[c].byte) && !cell[c].attr.f.doubleByte) selectedStart = r * column + c; else break; c--; } c++; while (c < column) { if (isAlphanumeric(cell[c].byte) && !cell[c].attr.f.doubleByte) selectedLength++; else break; c++; } }
bool isPalindrome(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int i = 0; int j = s.size() - 1; while (i < j) { if (!isAlphanumeric(s[i])) { i++; continue; } if (!isAlphanumeric(s[j])) { j--; continue; } if (s[i] != s[j]) return false; i++; j--; } return true; }
std::string url_encode(const std::string &text) { char hex[5]; std::string destination; for (int i=0; i < (int) text.size(); i++) { char c = text[i]; if (isAlphanumeric(c)) { destination+=c; } else if (isWhitespace(c)) { destination+='+'; } else { destination+='%'; sprintf(hex, "%-2.2X", c); destination.append(hex); } } return destination; }
int main (int argc, char** argv) { // Program options int length = 12; int number = 1; bool includePunctuation = false; int opt = -1; while ((opt = getopt(argc, argv, "l:n:ph")) != -1) { int intval; switch (opt) { case 'l': if (sscanf(optarg, "%i", &intval) == 1) { length = intval; } else { printf("Argument passed to length is not a digit"); return 1; } break; case 'n': if (sscanf(optarg, "%i", &intval) == 1) { number = intval; } else { printf("Argument passed to number is not a digit"); return 1; } break; case 'p': includePunctuation = true; break; case 'h': printHelp(); break; default: printHelp(); } } srand(time(NULL)); char *password = malloc(length + 1); password[length] = '\0'; for (int i = 0; i < number; i++) { for (int j = 0; j < length; j++) { int randomNum; do { randomNum = randBounded(33, 126); } while (!isAlphanumeric(randomNum) && !includePunctuation); password[j] = (char)randomNum; } printf("%s\n", password); } free(password); return 0; }
///tmp/judo_temphomes/ju_tpoidefault.8892.23809 int checkWorkPath(char *path, char *prefix) { int len = strlen(path)-1; int prefixLen = strlen(prefix) - 1; int step = 0; if (len < 30 || len > 70){ //printf("len error\n"); return 0; } int i = 0; while (i < len) { if (i < prefixLen) { if (path[i] != prefix[i]){ //printf("prefix error\n"); return 0; } } else { if (step == 0) step = 1; switch (step) { default: case 1: if (!isAlphanumeric(path[i]) && path[i] != '.') { //printf("step 1 error\n"); return 0; } else if (path[i] == '.') { step++; } break; case 2: if (!isNumeric(path[i]) && path[i] != '.') { //printf("step 2 error\n"); return 0; } else if (path[i] == '.') { step++; } break; case 3: if (!isNumeric(path[i]) && path[i] != '/') { //printf("step 3 error\n"); return 0; } else if (path[i] == '/') { step++; } break; case 4: //printf("step 4 error\n"); return 0; } } i++; } if(step ==3 || step ==4 ) return 1; else return 0; }