-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
120 lines (92 loc) · 2.01 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "biblioteca.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc,char *argv[])
{
cumparaturi *p,*q,*head_cumparaturi;
supermarket *m,*n,*head_supermarket;
cos_cumparaturi *head_cos,*s,*t;
Tree *root;
FILE *f;
if((f=fopen("cerinte.txt","r"))==NULL)
{
printf("Nu s-a putut deschide fisierul");
exit(1);
}
int v[10],buget,i,x;
for(i=0;i<6;i++)
fscanf(f,"%d",&v[i]);
fscanf(f,"%d",&buget);
fclose(f);
if((f=fopen("date1.txt","r"))==NULL)
{
printf("Nu s-a putut deschide fisierul");
exit(1);
}
creare_stocuri(&m,&n,&head_supermarket,f);
fclose(f);
if(v[0]==1)//cerinta 1
{if((f=fopen("date2.txt","r"))==NULL)
{
printf("Nu s-a putut deschide fisierul");
exit(1);
}
creare_lista_cumparaturi(&p,&q,&head_cumparaturi,f);
fclose(f);
}
if(v[1]==1)//cerinta 2
{if((f=fopen("date1.txt","r"))==NULL)
{
printf("Nu s-a putut deschide fisierul");
exit(1);
}
eliminare(head_cumparaturi,head_supermarket,f);
fclose(f);
}
if(v[2]==1)//cerinta 3
{
buy(head_cumparaturi,head_supermarket,&head_cos,buget);
}
if(v[3]==1)//cerinta 4
{
unlimited_money(&head_cumparaturi,head_supermarket,&head_cos,f);
}
if(v[4]==1) //cerinta 5
{x=numarare(head_cos);
int b[x+1];
ordonare(b,x,head_cos);
if((f=fopen("temp_arbore.in","w"))==NULL)
{
printf("Nu s-a putut deschide fisierul");
exit(1);
}
for(i=0;i<x;i++)
fprintf(f," %d ",b[i]);
fclose(f);
if((f=fopen("temp_arbore.in","r"))==NULL)
{
printf("Nu s-a putut deschide fisierul");
exit(1);
}
root=arbore(x,f);
fclose(f);
}
//if(v[5]==1)
Stiva *top;
int nr;
nr=nr_elemente(head_supermarket);
int *r;
r=malloc(sizeof(int)*nr);
cerinta_6(top,head_supermarket,r);
if((f=fopen("rezultate.out","w"))==NULL)
{
printf("Nu s-a putut deschide fisierul");
exit(1);
}
afisare(head_cumparaturi,head_cos,v,root,f);
if(v[5]==1)
afisare_elem_consecutive(r,nr,f);
fclose(f);
return 0;
}