Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include<stdlib.h>
  4. using namespace std;
  5.  
  6.  
  7. struct List
  8. {
  9. int num;
  10. int st;
  11. List* next;
  12. };
  13. void add(List* l, int n, int s)
  14. {
  15. List* q = l;
  16. List* w = new List();
  17. w->num = n;
  18. w->st = s;
  19. while(q->next != NULL)
  20. q = q->next;
  21. q->next = w;
  22. w->next = NULL;
  23. }
  24.  
  25. int find(List* l, int a)
  26. {
  27. List* w = l;
  28. while (w->num != a)
  29. w = w->next;
  30. if (w->st <= 3)
  31. return w->st;
  32. find(l, w->st);
  33. }
  34.  
  35.  
  36. void deletelist(List* l)
  37. {
  38. List* q = l->next;
  39. while (q->next != NULL)
  40. {
  41. delete l;
  42. l = q;
  43. q = q->next;
  44. }
  45. delete q;
  46. }
  47.  
  48. int main()
  49. {
  50. FILE* f = fopen("7-1.txt","rt");
  51. int n = 0;
  52. fscanf(f, "%d", &n);
  53. List* l = new List();
  54. int a[100], m = 0, k = 0, fl = 0, i = 0;
  55. for (i = 0; i <= n; i++)
  56. a[i] = 0;
  57. i = 0;
  58. while (!(feof(f)) && i < n)
  59. {
  60. fscanf(f, "%d %d", &m, &k);
  61. if (k == 0)
  62. {
  63. if (fl == 0)
  64. {
  65. cout << "this students should be punished:" << '\n';
  66. fl = 1;
  67. }
  68. a[m] = 1;
  69. cout << m << '\n';
  70. }
  71. else
  72. {
  73. add(l, m, k);
  74. a[m] = 1;
  75. }
  76. i++;
  77. }
  78. if (i < n - 1)
  79. {
  80. if (fl == 0)
  81. cout << "this students should be punished:" << '\n';
  82. for (int j = 1 ; j <= n; j++)
  83. if (a[j] == 0)
  84. cout << j << '\n';
  85. }
  86. List* w = l;
  87. while (w->next != NULL)
  88. {
  89. if (w->st > 3)
  90. w->st = find(l, w->st);
  91. w = w->next;
  92. }
  93. if (w->st > 3)
  94. w->st = find(l, w->st);
  95. if (l->next != NULL)
  96. cout << "others:" << '\n';
  97. w = l;
  98. while(w->next != NULL)
  99. {
  100. w = w->next;
  101. if (w->num > 3)
  102. cout << w->num << " copied from " << w->st << '\n';
  103. }
  104. deletelist(l);
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement