fork(1) download
  1. #include <stdio.h>
  2.  
  3. // for readability not advocating the
  4. // usage of #define booleans etc
  5. #define TRUE 1
  6. #define FALSE 0
  7.  
  8. int isVowel (char c)
  9. {
  10. switch (c)
  11. {
  12. case 'a': return TRUE;
  13. case 'e': return TRUE;
  14. case 'i': return TRUE;
  15. case 'o': return TRUE;
  16. case 'u': return TRUE;
  17. case 'A': return TRUE;
  18. case 'E': return TRUE;
  19. case 'I': return TRUE;
  20. case 'O': return TRUE;
  21. case 'U': return TRUE;
  22. }
  23.  
  24. return FALSE;
  25. }
  26.  
  27. int hasOrderedVowels (char *str)
  28. {
  29. char c1, c2;
  30.  
  31. c1 = *str;
  32. c2 = *(++str);
  33.  
  34. // ignore words beginning in vowels other then 'a' or 'A'
  35. if ((isVowel(c1)) && !(c1 == 'a' || c1 == 'A'))
  36. // && !(!(c1 == 'a' && c1 == 'A') && (c1 == 'a' || c1 == 'A')))
  37. {
  38. return FALSE;
  39. }
  40.  
  41. do {
  42. // ignore case of `c1`
  43. if (c1 >= 'a')
  44. c1 -= 32;
  45.  
  46. // ignore case of `c2`
  47. if (c2 >= 'a')
  48. c2 -= 32;
  49.  
  50. // compare vowels and increment
  51. // pointers as appropriate
  52. if (isVowel(c1) && isVowel(c2))
  53. {
  54. // if we have found a vowel less then or equal to current
  55. // then they are not in order/more then one, if we have found
  56. // a 'U' and there are more vowels then this would be a duplicate
  57. if (c2 <= c1 || c1 == 'U')
  58. return FALSE;
  59.  
  60. c1 = c2;
  61. }
  62. else if (isVowel(c2)) // found first vowel
  63. {
  64. if (!(c2 == 'a' || c2 == 'A'))
  65. {
  66. return FALSE;
  67. }
  68. c1 = c2;
  69. }
  70. else if (!isVowel(c1))
  71. {
  72. c1 = *(str += 2);
  73. }
  74. c2 = *(++str);
  75. }
  76. while (c2 != '\0');
  77.  
  78. return (c1 == 'U' || c1 == 'u');
  79. }
  80.  
  81. int main ()
  82. {
  83. char *str[] = {"aeiou", "facecious", "chimpanze", "baboon"};
  84. int i = 0;
  85.  
  86. for (; i<4; i++)
  87. {
  88. printf ("%s: %i\n", str[i], hasOrderedVowels(str[i]));
  89. }
  90.  
  91. return 0;
  92. }
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
aeiou: 1
facecious: 1
chimpanze: 0
baboon: 0