Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- #include <locale.h>
- #include <windows.h>
- struct list
- {
- list(char _elem = 0, list *_next = NULL) : elem(_elem), next(_next) {}
- char elem;
- list *next;
- };
- void print(list *l);
- void unique(list *l);
- char input(const char *path, list *l);
- int main()
- {
- setlocale(0, "");
- list *S = new list();
- input("symbols.txt", S);
- //unique(S);
- print(S);
- return 0 * _getch();
- }
- char input(const char *path, list *l)
- {
- FILE *stream = NULL;
- fopen_s(&stream, path, "r");
- if (stream)
- {
- char elem = 0;
- list *d = new list();
- // Считываем все символы из файла.
- for (list *p = l; fscanf_s(stream, "%c", &elem, 1) != EOF && p; )
- {
- bool isUniq = true;
- for (list *q = d; q && isUniq; q = q->next)
- if (elem == q->elem) isUniq = false;
- if (!isUniq)
- {
- for (list **z = &l; *z; z = &((*z)->next))
- {
- if ((*z)->elem == elem)
- {
- list *t = (*z)->next;
- delete *z;
- *z = t;
- }
- }
- }
- else
- {
- p->elem = elem;
- p->next = new list();
- p = p->next;
- list *ld = d;
- for ( ; ld->next; ld = ld->next);
- ld->elem = elem;
- ld->next = new list();
- }
- }
- fclose(stream);
- return 0;
- }
- else
- {
- perror("Завершение работы программы");
- return -1;
- }
- }
- void unique(list *l)
- {
- for (list *q = l; q && q->next; q = q->next)
- {
- int dup_c = 0;
- for (list *t = q->next; t->next; )
- {
- if (t->next->elem == q->next->elem)
- {
- list *w = t->next->next;
- delete t->next;
- t->next = w;
- dup_c++;
- int a = 1;
- }
- else t = t->next;
- }
- if (dup_c)
- {
- list *w = q->next->next;
- delete q->next;
- q->next = w;
- int b = 2;
- }
- int c = 3;
- }
- }
- void print(list *l)
- {
- printf_s("Результат работы программы: \n");
- for (list *p = l; p; p = p->next)
- printf_s("%c", p->elem);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement