Advertisement
greannmhar

послед 41 сдана

Sep 26th, 2023 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. int max(int a, int b);
  3. int max(int a, int b)
  4. {
  5.     if(a > b)
  6.     {
  7.         return a;
  8.     }
  9.     return b;
  10. }
  11. int main(void)
  12. {
  13.     FILE* fin;
  14.     int ans = 0, cnt = 0, prev, cur;
  15.     if((fin = fopen("in.txt", "rt")) == NULL)
  16.     {
  17.         printf("Cant open file\n");
  18.     }
  19.    
  20.     if(fscanf(fin, "%d", &prev) != 1)
  21.     {
  22.         printf("wrong file format");
  23.     }
  24.     while(fscanf(fin, "%d", &cur) == 1)
  25.     {
  26.         if(prev == cur)
  27.         {
  28.             cnt++;
  29.         }
  30.         else
  31.         {
  32.             ans = max(ans, cnt);
  33.             cnt = 0;
  34.         }
  35.         prev = cur;
  36.     }
  37.     ans = max(ans, cnt);
  38.     ans++;
  39.     fclose(fin);
  40.     printf("%d\n", ans);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement