Created
May 16, 2021 16:24
-
-
Save poseidon4o/658cedaa71aee5bef86ac7a0689fb4f2 to your computer and use it in GitHub Desktop.
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 <cctype> | |
#include <cstring> | |
#include <iostream> | |
typedef int (*Validator)(int); | |
bool isValidRegistration(char reg[9]) { | |
const Validator validators[9] = {isupper, isupper, isdigit, isdigit, isdigit, isdigit, isupper, isupper }; | |
const int len = strlen(reg); | |
const Validator *check = len == 8 ? validators : validators + 1; | |
for (int c = 0; c < len; c++) { | |
if (!check[c](reg[c])) { | |
return false; | |
} | |
} | |
return true; | |
} | |
int main() { | |
char reg[6][9] = {"C1234AB", "XY1111YX", "111145", "ABC34DEF", "ABCDEF", "C11D"}; | |
for (int c = 0; c < sizeof(reg) / sizeof(reg[0]); c++) { | |
std::cout << reg[c] << " - " << isValidRegistration(reg[c]) << '\n'; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment