DEV Community

Discussion on: Daily Challenge #205 - Consonant String Value

Collapse
 
aminnairi profile image
Amin • Edited

C

#include <stdio.h>

int isVowel(const char letter);
int highestConsonantSubstring(const char* string);

int main(void) {
    printf("%d\n", highestConsonantSubstring("strength"));
    printf("%d\n", highestConsonantSubstring("chruschtschov"));

    return 0;
}

int isVowel(const char letter) {
    switch (letter) {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
            return 1;

        default:
            return 0;
    }
}

int highestConsonantSubstring(const char* string) {
    const char* letter = string;

    unsigned int highest = 0;
    unsigned int current = 0;

    for (const char* letter = string; *letter; letter++) {
        if (!isVowel(*letter)) {
            current += *letter - 96;
            continue;
        }

        if (highest < current) {
            highest = current;
        }

        current = 0;
    }

    return highest;
}