Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <conio.h>
  6. #include <locale.h>
  7.  
  8.  
  9. typedef struct Team {
  10. int Name;
  11. int City;
  12. int Wins;
  13. int Loses;
  14. int Draws;
  15. int Points;
  16. struct Team*Next;
  17. }Team;
  18. typedef struct List
  19. {
  20. Team*First;
  21. }List;
  22.  
  23. void Add(List* L, int *N) {
  24. Team*Current = L->First;
  25. Team *time = (Team*)calloc(1, sizeof(Team));
  26. printf("Name ");
  27. scanf_s("%d", &time->Name);
  28. printf("\nCity ");
  29. scanf_s("%d", &time->City);
  30. printf("\nWins ");
  31. scanf_s("%d", &time->Wins);
  32. printf("\nLoses ");
  33. scanf_s("%d", &time->Loses);
  34. printf("\nDraws");
  35. scanf_s("%d", &time->Draws);
  36. printf("\nPoints ");
  37. scanf_s("%d", &time->Points);
  38. while (Current->Next != NULL)
  39. Current =Current->Next;
  40. Current->Next = time;
  41. time->Next = NULL;
  42.  
  43. (*N)++;
  44. }
  45. Team* Find(List*L, int *N) {
  46. printf("\Print Team name");
  47. int i, n;
  48. Team* Current=L->First;
  49. scanf_s("%d", &n);
  50. while ((Current->Name != n)&&(Current!=NULL))
  51.  
  52. Current = Current->Next;
  53.  
  54. if (Current->Name != n)
  55. return 0;
  56. FILE* fl;
  57. fopen_s(&fl, "test.txt", "a");
  58.  
  59. fprintf(fl, "\n%d ", Current->Name);
  60. fprintf(fl, "%d ", Current->City);
  61. fprintf(fl, "%d ", Current->Wins);
  62. fprintf(fl, "%d ", Current->Loses);
  63. fprintf(fl, "%d ", Current->Draws);
  64. fprintf(fl, "%d \n", Current->Points);
  65. fclose(fl);
  66.  
  67. return Current;
  68.  
  69. }
  70.  
  71. void Insert(List* L, int*N)
  72. {
  73. printf("Print place where to insert element");
  74. int m,i;
  75. scanf("%d",&m);
  76. Team* Current=L->First;
  77.  
  78. Team *time=(Team*)calloc(1,sizeof(Team));
  79. printf("Name ");
  80. scanf_s("%d", &time->Name);
  81. printf("\nCity ");
  82. scanf_s("%d", &time->City);
  83. printf("\nWins ");
  84. scanf_s("%d", &time->Wins);
  85. printf("\nLoses ");
  86. scanf_s("%d", &time->Loses);
  87. printf("\nDraws ");
  88. scanf_s("%d", &time->Draws);
  89. printf("\Points");
  90. scanf_s("%d", &time->Points);
  91. if (m == *N+1)
  92. while (Current->Next!=NULL) {
  93. Current= Current->Next;
  94. }
  95. if (m == 0) {
  96. time->Next = L->First;
  97. L->First=time;
  98. }
  99. if (m ==* N) {
  100. Current->Next = time;
  101. time->Next == NULL;
  102.  
  103. }
  104. if ((m != *N+1) && (m != 0)) {
  105. for (int i = 0; i < m-1; i++)
  106. Current = Current->Next;
  107. time->Next = Current->Next;
  108. Current->Next = time;
  109. }
  110. (*N)++;
  111. }
  112. List filtr(List*L, int*N) {
  113. printf("\n Print filter number ");
  114. List now;
  115. now.First = NULL;
  116. Team* Current=L->First,*Current2=now.First;
  117. int otv,p;
  118. int i;
  119. scanf_s("%d", &p);
  120. printf("\n1->\n2-<\n3-=");
  121. scanf_s("%d", &otv);
  122. *N = 0;
  123. switch (otv) {
  124. case 1: while (Current != NULL) {
  125.  
  126. if (Current->Wins > p) {
  127. if (now.First == NULL) {
  128. now.First = (Team*)calloc(1, sizeof(Team));
  129. now.First = Current;
  130. (*N)++;
  131. Current2 = now.First;
  132. Current= Current->Next;
  133. continue;
  134. }
  135. if(Current2!=NULL) {
  136. Current2->Next = (Team*)calloc(1, sizeof(Team));
  137. Current2->Next = Current;
  138. Current2 = Current2->Next;
  139. (*N)++;
  140. }
  141. }
  142. Current = Current->Next;
  143. }
  144. break;
  145. case 2: while (Current != NULL) {
  146.  
  147. if (Current->Wins < p) {
  148. if (now.First == NULL) {
  149. now.First = (Team*)calloc(1, sizeof(Team));
  150. now.First = Current;
  151. (*N)++;
  152. Current2 = now.First;
  153. Current = Current->Next;
  154. continue;
  155. }
  156. if (Current2 != NULL) {
  157. Current2->Next = (Team*)calloc(1, sizeof(Team));
  158. Current2->Next = Current;
  159. Current2 = Current2->Next;
  160. (*N)++;
  161. }
  162. }
  163. Current = Current->Next;
  164. }
  165. break;
  166. case 3: while (Current != NULL) {
  167.  
  168. if (Current->Wins== p) {
  169. if (now.First == NULL) {
  170. now.First = (Team*)calloc(1, sizeof(Team));
  171. now.First = Current;
  172. (*N)++;
  173. Current = now.First;
  174. Current = Current->Next;
  175. continue;
  176. }
  177. if (Current2 != NULL) {
  178. Current2->Next = (Team*)calloc(1, sizeof(Team));
  179. Current2->Next = Current;
  180. Current2 = Current2->Next;
  181. (*N)++;
  182. }
  183. }
  184. Current = Current->Next;
  185. }
  186. break;
  187. }
  188. return now;
  189.  
  190. }
  191.  
  192.  
  193.  
  194. void Remove(List* L,int*N,Team*Delete)
  195. {
  196. Team*Current=L->First;
  197. if(Delete->Name!=L->First->Name){
  198. if (Current->Name !=Delete->Name) {
  199. while (Current->Next->Name != Delete->Name)
  200. Current = Current->Next;
  201.  
  202.  
  203.  
  204. }
  205. Current->Next = Current->Next->Next;
  206.  
  207. }
  208. else
  209. L->First = Current->Next;
  210. (*N)--;
  211. }
  212. void save(List* L,int*N) {
  213. FILE* fl=fopen("test1.txt", "a");
  214. int i;
  215. Team*Current;
  216. Current= L->First;
  217. fprintf(fl, "\n ");
  218.  
  219. for (i = 0; i < *N; i++) {
  220. fprintf(fl, "%d ", Current->Name);
  221. fprintf(fl, "%d ", Current->City);
  222. fprintf(fl, "%d ", Current->Wins);
  223. fprintf(fl, "%d ", Current->Loses);
  224. fprintf(fl, "%d ", Current->Draws);
  225. fprintf(fl, "%d \n",Current->Points);
  226. Current = Current->Next;
  227. }
  228. fclose(fl);
  229.  
  230. }
  231. void load(List*L,int* N) {
  232. FILE* fl=fopen("test.txt","r");
  233. int i;
  234. Team*Current = L->First;
  235. fscanf_s(fl, "%d", N);
  236.  
  237. for (i = 0; i <*N; i++) {
  238. fscanf_s(fl, "%d",&Current->Name);
  239. fscanf_s(fl, "%d",& Current->City);
  240. fscanf_s(fl, "%d", &Current->Wins);
  241. fscanf_s(fl, "%d", &Current->Loses);
  242. fscanf_s(fl, "%d", &Current->Draws);
  243. fscanf_s(fl, "%d", &Current->Points);
  244. Current->Next = (Team*)calloc(1,sizeof(Team));
  245. if (1+i == *N)
  246. Current->Next = NULL;
  247.  
  248. Current = Current->Next;
  249. }
  250.  
  251. fclose(fl);
  252. }
  253.  
  254. int main()
  255. {
  256. int N;
  257. List L;
  258. Team* c;
  259. L.First = (Team*)calloc(1,sizeof(Team));
  260. load(&L,&N);
  261. save(&L,&N);
  262. Insert(&L, &N);
  263. save(&L, &N);
  264. Remove(&L, &N, Find(&L, &N));
  265. save(&L, &N);
  266. Add(&L, &N);
  267. save(&L, &N);
  268. save(&filtr(&L, &N),&N );
  269.  
  270. free(L.First);
  271. system("pause");
  272. return 0;
  273. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement