Skip to content

Instantly share code, notes, and snippets.

@squgeim
Created September 14, 2018 04:28
Show Gist options
  • Save squgeim/0be0415dab2fafa66218d1778fceb3aa to your computer and use it in GitHub Desktop.
Save squgeim/0be0415dab2fafa66218d1778fceb3aa to your computer and use it in GitHub Desktop.
Vowels Sample answer
#include<stdio.h>
#include<string.h>
#define TRUE 1
#define FALSE 0
#define LENGTH_LIMIT 1000
int is_char_vowel(char c) {
switch (c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return TRUE;
default:
return FALSE;
}
}
int main(int argc, char **argv) {
int i;
char current_char;
char *vowel_order = "aeiou";
char last_vowel;
int last_vowel_idx = -1;
int is_correct;
for (i = 0, is_correct = TRUE; i < LENGTH_LIMIT; i++) {
current_char = argv[1][i];
if (current_char == '\0') {
break;
}
if (current_char == last_vowel) {
continue;
}
if (is_char_vowel(current_char)) {
if (
last_vowel_idx != -1 &&
current_char != vowel_order[last_vowel_idx + 1]
) {
is_correct = FALSE;
break;
}
last_vowel = current_char;
last_vowel_idx = last_vowel_idx == -1 ? 0 : last_vowel_idx + 1;
}
}
if (!is_correct || last_vowel_idx != 4) {
printf("False\n");
return 0;
}
printf("True\n");
return 0;
}
@squgeim
Copy link
Author

squgeim commented Sep 14, 2018

Given a word, check if it has all vowels in order (a, e, i, o, u). The words are only provided in lower case.
Example:
facetious => true
precarious => false
apple => false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment