Skip to content

Instantly share code, notes, and snippets.

@cciollaro
Created May 29, 2013 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cciollaro/5670532 to your computer and use it in GitHub Desktop.
Save cciollaro/5670532 to your computer and use it in GitHub Desktop.
personal script that checks if a string meets a specified order. example usage: g++ order_compliant.c -o order_compliant cat /usr/share/dict/words | ./order_compliant > accepted_words.txt
#include <iostream>
#include <string>
#include <cstring>
int complies(const char * word){
char order[30];
int wordLength, wordPointer, orderLength, orderPointer;
strcpy(order, "qazwsxedcrfvtgbyhnujmikolp");
wordLength = strlen(word);
orderLength = strlen(order);
orderPointer = 0;
for(wordPointer = 0; wordPointer < wordLength; wordPointer++){
while(1){
if(tolower(word[wordPointer]) == order[orderPointer]){
orderPointer++; //increment even if it's found because I don't accept doubles
break;
} else {
orderPointer++;
}
if(orderPointer == orderLength + 1){
return 0;
}
}
}
return(1);
}
int main(int argc, char * argv[]){
std::string line;
while(std::getline(std::cin, line)){
if(complies(line.c_str())){
std::cout << line << std::endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment