Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAXLINE 300
- void getline(char s[][MAXLINE], int lim, int nstring, FILE *fileName)
- {
- int i, c;
- s[nstring][0] = ' ';
- for(i = 1; i < MAXLINE && (c = fgetc(fileName)) != EOF && c != '\n'; ++i)
- s[nstring][i] = c;
- s[nstring][i] = ' ';
- ++i;
- if (c == '\n')
- {
- s[nstring][i] = c;
- ++i;
- }
- s[nstring][i] = '\0';
- }
- int isVowel(char s)
- {
- if (s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u' || s == 'y')
- return 1;
- return 0;
- }
- int main()
- {
- FILE *inFile = fopen("input.txt", "r");
- FILE *outFile = fopen("output.txt", "w");
- int N;
- int input;
- fscanf(inFile, "%d", &N);
- while ((input = fgetc(inFile)) != '\n')
- input = fgetc(inFile);
- char array[N][MAXLINE];
- for (int i = 0; i < N; ++i)
- getline(array, MAXLINE, i, inFile);
- int count = 0;
- int max = 0;
- char* result[N];
- int index = 0;
- for (int i = 0; i < N; ++i)
- {
- for (int j = 3; array[i][j] != '\n'; ++j)
- {
- if (!isVowel(array[i][j]) && !isVowel(array[i][j-3]) && isVowel(array[i][j-1]) && isVowel(array[i][j-2]))
- ++count;
- }
- if (count > max){
- index = 0;
- for (int i = 0; i < N; ++i)
- result[i] = " ";
- for (int j = 1; array[i][j] != '\n'; ++j){
- if (array[i][j] == ' ')
- array[i][j] = '\0';
- array[i][j-1] = array[i][j];
- }
- result[index++] = array[i];
- }
- else if (count == max){
- for (int j = 1; array[i][j] != '\n'; ++j){
- if (array[i][j] == ' ')
- array[i][j] = '\0';
- array[i][j-1] = array[i][j];
- }
- result[index++] = array[i];
- }
- max = count > max ? count : max;
- count = 0;
- }
- for (int i = 0; i < N; ++i){
- if (strcmp(result[i], " ") != 0)
- fprintf(outFile, "%s\n", result[i]);
- }
- fclose(inFile);
- fclose(outFile);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment