Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "String.h"
  3. #include "stdlib.h"
  4.  
  5.  
  6. typedef struct
  7. {
  8.  
  9. char nume[20];
  10.  
  11.  
  12. }angajati;
  13.  
  14. typedef struct
  15. {
  16. char pro[20];
  17. int nr;
  18. angajati a[30];
  19.  
  20. struct proiect *next;
  21.  
  22.  
  23. }proiect;
  24.  
  25. proiect *rad;
  26. void adaugaproiect(char *pro)
  27. {
  28. proiect *nod;
  29. nod = (proiect*)malloc(sizeof(proiect));
  30. strcpy(nod->pro,pro);
  31. nod->nr = 0;
  32. nod->next = NULL;
  33.  
  34. if (rad ==NULL)
  35. {
  36. rad = nod;
  37.  
  38. }
  39. else {
  40. nod->next = rad;
  41. rad = nod;
  42.  
  43. }
  44.  
  45.  
  46. }
  47.  
  48.  
  49. void adaugaangajati(char *pro,char *nume)
  50. {
  51. proiect *aux= rad;
  52. angajati ang;
  53. int k = 0;
  54. strcpy(ang.nume, nume);
  55. while (aux != NULL)
  56. {
  57. if (strcmp(aux->pro, pro) == 0)
  58. {
  59. if (aux->nr != 0) {
  60. for (int i = 0; i < aux->nr; i++)
  61. if (strcmp(aux->a[i].nume, nume) < 0)
  62. {
  63. for (int j = aux->nr; j > i; j--)
  64. {
  65. aux->a[j] = aux->a[j - 1];
  66. }
  67. k = 1;
  68. aux->a[i] = ang;
  69. }
  70. if (k == 0)
  71. aux->a[aux->nr] = ang;
  72. }
  73. else
  74. aux->a[aux->nr] = ang;
  75.  
  76. aux->nr++;
  77. return;
  78. }
  79. aux = aux->next;
  80. }
  81.  
  82.  
  83. }
  84. void transfera(char *numeproj, char *nume)
  85. {
  86. proiect *aux = rad;
  87.  
  88. while (aux != NULL)
  89. {
  90. for (int i = 0; i < aux->nr; i++)
  91. {
  92. if (strcmp(aux->a[i].nume, nume) == 0)
  93. {
  94. for (int j = i; j < aux->nr; j++)
  95. {
  96. aux->a[j] = aux->a[j + 1];
  97.  
  98. }
  99. aux->nr--;
  100.  
  101. }
  102.  
  103. }
  104. aux = aux->next;
  105. }
  106. adaugaangajati(numeproj, nume);
  107. }
  108.  
  109.  
  110. void afisarepro()
  111. {
  112. proiect *aux = rad;
  113.  
  114. while (aux != NULL)
  115. {
  116. printf("%s ", aux->pro);
  117.  
  118. for (int i = 0; i < aux->nr; i++)
  119. printf("%s ", aux->a[i].nume);
  120.  
  121. printf("\n");
  122. aux = aux->next;
  123. }
  124. }
  125.  
  126.  
  127.  
  128. void main()
  129. {
  130. int nrproj, nrang;
  131. char numeproj[20], nume[30];
  132.  
  133. scanf("%d", &nrproj);
  134. getchar();
  135.  
  136.  
  137. for (int i = 0; i < nrproj; i++)
  138. {
  139. scanf("%s", numeproj);
  140. scanf("%d", &nrang);
  141. getchar();
  142. adaugaproiect(numeproj);
  143.  
  144. for (int j = 0; j < nrang; j++)
  145. {scanf("%s", nume);
  146. adaugaangajati(numeproj, nume);
  147. }
  148.  
  149.  
  150. }
  151. afisarepro();
  152. char numeproject[20], numeangajat[30];
  153. scanf("%s", numeproject);
  154. scanf("%s", numeangajat);
  155. transfera(numeproject, numeangajat);
  156. afisarepro();
  157.  
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement