58 lines
1.1 KiB
C
58 lines
1.1 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <stdint.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
int main() {
|
||
|
//load input string
|
||
|
FILE *file = fopen("input", "r");
|
||
|
if (file == NULL) {
|
||
|
perror("main: error opening file.");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
//string exclusions
|
||
|
char *ab = "ab";
|
||
|
char *cd = "cd";
|
||
|
char *pq = "pq";
|
||
|
char *xy = "xy";
|
||
|
|
||
|
uint32_t ncount = 0;
|
||
|
uint8_t double_check = 0;
|
||
|
uint8_t vowel_check = 0;
|
||
|
char input[256];
|
||
|
while (fgets(input, sizeof(input), file) != NULL) {
|
||
|
//string exclusion test
|
||
|
if (strstr(input, ab) || strstr(input, cd) || strstr(input, pq) || strstr(input, xy)) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
//double letter test
|
||
|
double_check = 0;
|
||
|
for (uint8_t i = 0; i < strlen(input); i++) {
|
||
|
if (input[i] == input[i+1]) {
|
||
|
double_check = 1;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//three vowel test
|
||
|
vowel_check = 0;
|
||
|
for (uint8_t i = 0; i < strlen(input); i++) {
|
||
|
if (input[i] == 'a' || input[i] == 'e' || input[i] == 'i' || input[i] == 'o' || input[i] == 'u')
|
||
|
vowel_check++;
|
||
|
}
|
||
|
|
||
|
if (double_check == 1 && vowel_check >= 3)
|
||
|
ncount++;
|
||
|
}
|
||
|
if (ferror(file)) {
|
||
|
perror("main: error reading file.");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
printf("ncount: %i\n", ncount);
|
||
|
return 0;
|
||
|
}
|
||
|
|