Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3.  
  4. struct list
  5. {
  6.     char elem;
  7.     list* next;
  8.     list* prev;
  9. };
  10.  
  11. void read(FILE* f, list** p)
  12. {
  13.     char c = getc(f);
  14.     if (c != '.')
  15.     {
  16.         list* ph = new list;
  17.         *p = ph;
  18.         ph->elem = c;
  19.         ph->next = ph;
  20.         ph->prev = ph;
  21.         c = getc(f);
  22.         while (c != '.')
  23.         {
  24.             ph->next = new list;
  25.             ph->next->prev = ph;
  26.             ph = ph->next;
  27.             ph->elem = c;
  28.             ph->next = *p;
  29.             (*p)->prev = ph;
  30.             c = getc(f);
  31.         }
  32.     }
  33. }
  34.  
  35. int result(list* ph)
  36. {
  37.     int res = 0;
  38.     list* p = ph;
  39.     do
  40.     {
  41.         if (ph->elem == ph->next->elem)
  42.             res = 1;
  43.         ph = ph->next;
  44.  
  45.     } while (ph != p && res != 1);
  46.     return res;
  47. }
  48.  
  49. int main()
  50. {
  51.  
  52.     int i = 0;
  53.     list* p = NULL;
  54.  
  55.     FILE* f;
  56.  
  57.     if (!(fopen_s(&f, "file1.txt", "r")))
  58.         read(f, &p);
  59.     else
  60.         printf_s("Не найден файл");
  61.  
  62.     i = result(p);
  63.     printf_s("%d", i);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement