Created
May 29, 2013 14:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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