Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include<stdlib.h>
- using namespace std;
- struct List
- {
- int num;
- int st;
- List* next;
- };
- void add(List* l, int n, int s)
- {
- List* q = l;
- List* w = new List();
- w->num = n;
- w->st = s;
- while(q->next != NULL)
- q = q->next;
- q->next = w;
- w->next = NULL;
- }
- int find(List* l, int a)
- {
- List* w = l;
- while (w->num != a)
- w = w->next;
- if (w->st <= 3)
- return w->st;
- find(l, w->st);
- }
- void deletelist(List* l)
- {
- List* q = l->next;
- while (q->next != NULL)
- {
- delete l;
- l = q;
- q = q->next;
- }
- delete q;
- }
- int main()
- {
- FILE* f = fopen("7-1.txt","rt");
- int n = 0;
- fscanf(f, "%d", &n);
- List* l = new List();
- int a[100], m = 0, k = 0, fl = 0, i = 0;
- for (i = 0; i <= n; i++)
- a[i] = 0;
- i = 0;
- while (!(feof(f)) && i < n)
- {
- fscanf(f, "%d %d", &m, &k);
- if (k == 0)
- {
- if (fl == 0)
- {
- cout << "this students should be punished:" << '\n';
- fl = 1;
- }
- a[m] = 1;
- cout << m << '\n';
- }
- else
- {
- add(l, m, k);
- a[m] = 1;
- }
- i++;
- }
- if (i < n - 1)
- {
- if (fl == 0)
- cout << "this students should be punished:" << '\n';
- for (int j = 1 ; j <= n; j++)
- if (a[j] == 0)
- cout << j << '\n';
- }
- List* w = l;
- while (w->next != NULL)
- {
- if (w->st > 3)
- w->st = find(l, w->st);
- w = w->next;
- }
- if (w->st > 3)
- w->st = find(l, w->st);
- if (l->next != NULL)
- cout << "others:" << '\n';
- w = l;
- while(w->next != NULL)
- {
- w = w->next;
- if (w->num > 3)
- cout << w->num << " copied from " << w->st << '\n';
- }
- deletelist(l);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement