Max_Leb

F2

Feb 2nd, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAXLINE 300
  5.  
  6. void getline(char s[][MAXLINE], int lim, int nstring, FILE *fileName)
  7. {
  8. int i, c;
  9. s[nstring][0] = ' ';
  10. for(i = 1; i < MAXLINE && (c = fgetc(fileName)) != EOF && c != '\n'; ++i)
  11. s[nstring][i] = c;
  12.  
  13. s[nstring][i] = ' ';
  14. ++i;
  15.  
  16. if (c == '\n')
  17. {
  18. s[nstring][i] = c;
  19. ++i;
  20. }
  21. s[nstring][i] = '\0';
  22. }
  23.  
  24. int isVowel(char s)
  25. {
  26. if (s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u' || s == 'y')
  27. return 1;
  28. return 0;
  29. }
  30.  
  31. int main()
  32. {
  33.  
  34. FILE *inFile = fopen("input.txt", "r");
  35. FILE *outFile = fopen("output.txt", "w");
  36. int N;
  37. int input;
  38. fscanf(inFile, "%d", &N);
  39. while ((input = fgetc(inFile)) != '\n')
  40. input = fgetc(inFile);
  41.  
  42. char array[N][MAXLINE];
  43.  
  44. for (int i = 0; i < N; ++i)
  45. getline(array, MAXLINE, i, inFile);
  46.  
  47. int count = 0;
  48. int max = 0;
  49. char* result[N];
  50. int index = 0;
  51. for (int i = 0; i < N; ++i)
  52. {
  53. for (int j = 3; array[i][j] != '\n'; ++j)
  54. {
  55. if (!isVowel(array[i][j]) && !isVowel(array[i][j-3]) && isVowel(array[i][j-1]) && isVowel(array[i][j-2]))
  56. ++count;
  57. }
  58. if (count > max){
  59. index = 0;
  60. for (int i = 0; i < N; ++i)
  61. result[i] = " ";
  62. for (int j = 1; array[i][j] != '\n'; ++j){
  63. if (array[i][j] == ' ')
  64. array[i][j] = '\0';
  65. array[i][j-1] = array[i][j];
  66. }
  67.  
  68.  
  69. result[index++] = array[i];
  70. }
  71. else if (count == max){
  72. for (int j = 1; array[i][j] != '\n'; ++j){
  73. if (array[i][j] == ' ')
  74. array[i][j] = '\0';
  75. array[i][j-1] = array[i][j];
  76. }
  77. result[index++] = array[i];
  78. }
  79.  
  80. max = count > max ? count : max;
  81. count = 0;
  82. }
  83.  
  84. for (int i = 0; i < N; ++i){
  85. if (strcmp(result[i], " ") != 0)
  86. fprintf(outFile, "%s\n", result[i]);
  87. }
  88.  
  89. fclose(inFile);
  90. fclose(outFile);
  91.  
  92.  
  93. return 0;
  94. }
  95.  
  96.  
  97.  
Advertisement
Add Comment
Please, Sign In to add comment