Advertisement
Toliak

task1

Dec 18th, 2018
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int checkWord(char *word) {
  6.     int length = strlen(word);
  7.  
  8.     // Проверяем, палиндром ли это
  9.     for (int i = 0; i < length / 2 + length % 2; i++) {
  10.         if (word[i] != word[length - i - 1])
  11.             return 0;
  12.     }
  13.  
  14.     return length;
  15. }
  16.  
  17. int main() {
  18.     FILE *fp;
  19.     char name[] = "task1.txt";
  20.  
  21.     fp = fopen(name, "r");
  22.  
  23.     char word[256];
  24.  
  25.     int maxLength = 0;
  26.  
  27.     // Считываем слова, пока они есть
  28.     while (fscanf(fp, "%s", word) != -1) {
  29.  
  30.         int newLength = checkWord(word);
  31.         if (newLength > maxLength)
  32.             maxLength = newLength;
  33.     }
  34.  
  35.     printf("%d", maxLength);
  36.  
  37.     fclose(fp);
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement