Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- struct stud
- {
- int id;
- char name[33];
- int mark;
- };
- struct Node
- {
- Node * next;
- Node * prev;
- stud * key;
- };
- struct List
- {
- Node * first;
- Node * last;
- };
- void swap(Node * a)
- {
- Node * b = a->next;
- a->next = a->prev;
- a->prev = b;
- }
- int push(List* l, stud* a)
- {
- Node * q = (Node *)malloc(sizeof(Node));
- if (!q)
- return 0;
- q->key = a;
- l->last->prev->next = q;
- q->prev = l->last->prev;
- q->next = l->last;
- l->last->prev = q;
- return 1;
- }
- List* list_new()
- {
- List* a = (List*)malloc(sizeof(List));
- Node* q = (Node*)malloc(sizeof(Node));
- Node* w = (Node*)malloc(sizeof(Node));
- q->prev = NULL;
- w->next = NULL;
- q->next = w;
- w->prev = q;
- a->first = q;
- a->last = w;
- return a;
- }
- void list_delete(List* l)
- {
- Node* a = l->first;
- Node* b;
- while (a != NULL)
- {
- b = a->next;
- free(a);
- a = b;
- }
- free(l);
- }
- int main()
- {
- int n = 0, k = 0;
- scanf("%i", &n);
- stud* arr = (stud*)malloc(n*sizeof(stud));
- List** mas = (List**)malloc(4 * sizeof(List*));
- for (int i = 0; i < 4; i++)
- mas[i] = list_new();
- int from = 0, to = 0;
- for (int i = 0; i < n; ++i)
- {
- scanf("%i%n%s%n", &arr[i].id, &from, arr[i].name, &to);
- scanf("%s%i", arr[i].name + to - from, &arr[i].mark);
- arr[i].name[to - from - 1] = ' ';
- push(mas[arr[i].mark - 2], &arr[i]);
- }
- for (int j = 0; j < 4; j++)
- {
- for (Node* i = mas[j]->first->next; i->next; i = i->next)
- printf("%i %s %i\n", i->key->id, i->key->name, i->key->mark);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment