Reformat for c/isogram for conciseness

This commit is contained in:
dwrz
2019-02-24 16:00:24 +00:00
parent 8519977157
commit 759b358035
+4 -10
View File
@@ -9,21 +9,15 @@ int length(const char string[]) {
char lowercase(char c) { char lowercase(char c) {
// Lowercase only ASCII uppercase chars. // Lowercase only ASCII uppercase chars.
if (c >= 65 && c <= 90) { if (c >= 65 && c <= 90) { return c + 32; }
return c + 32;
}
return c; return c;
} }
bool is_symbol_char(char c) { bool is_symbol_char(char c) {
// Catch chars that precede or follow alpha chars. // Catch chars that precede or follow alpha chars.
if (c < 65 || c > 122) { if (c < 65 || c > 122) { return true; }
return true;
}
// Catch chars intervening the upper and lowercase alpha chars. // Catch chars intervening the upper and lowercase alpha chars.
if (c > 90 && c < 97) { if (c > 90 && c < 97) { return true; }
return true;
}
return false; return false;
} }
@@ -36,7 +30,7 @@ bool is_isogram(const char phrase[]) {
for (int i = 0; i < length(phrase); i++) { for (int i = 0; i < length(phrase); i++) {
if (is_symbol_char(phrase[i])) { continue; } // Ignore non-alpha chars. if (is_symbol_char(phrase[i])) { continue; } // Ignore non-alpha chars.
if (char_map[lowercase(phrase[i]) - 97] != 0) { return false; } if (char_map[lowercase(phrase[i]) - 97] != 0) { return false; }
// Keep track of chars by incrementing the index value. // Increment the count for this char.
char_map[lowercase(phrase[i]) - 97]++; char_map[lowercase(phrase[i]) - 97]++;
} }
return true; return true;