-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC2020.c
More file actions
195 lines (192 loc) · 4.25 KB
/
C2020.c
File metadata and controls
195 lines (192 loc) · 4.25 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
FILE *fp;
typedef struct Node
{
char place[41];
int h;
int m;
struct Node *next;
} Node;
Node *head = NULL;
char place[41];
int h, m;
Node *makeNode(char place[], int h, int m)
{
Node *newNode = (Node *)malloc(sizeof(Node));
strcpy(newNode->place, place);
newNode->h = h;
newNode->m = m;
newNode->next = NULL;
return newNode;
}
Node *insertLast(Node *head, char place[], int h, int m)
{
Node *newNode = makeNode(place, h, m);
if (head == NULL)
{
head = newNode;
}
else
{
Node *temp = head;
while (temp->next != NULL)
{
temp = temp->next;
}
temp->next = newNode;
}
return head;
}
void menu()
{
printf("================================\n");
printf("CHUONG TRINH TRUY VET COVID 19\n");
printf("1. Nap file log lich su di chuyen\n");
printf("2. In ra lich su di chuyen\n");
printf("3. Tiem kiem lich su theo dia diem\n");
printf("4. Tim kiem lich su theo thoi gian\n");
printf("5. Kiem tra truy vet moi nhat\n");
printf("6. Thoat\n");
printf("================================\n");
}
void process1()
{
fp = fopen("log.txt", "r");
while (fscanf(fp, "%s %d %d", place, &h, &m) != EOF)
{
head = insertLast(head, place, h, m);
}
fclose(fp);
}
void process2()
{
Node *temp = head;
printf("%-50s%-10s%-10s\n", "Dia diem", "Gio", "Phut");
while (temp != NULL)
{
printf("%-50s%-10d%-10d\n", temp->place, temp->h, temp->m);
temp = temp->next;
}
}
void process3()
{
printf("Nhap dia diem can tim kiem: ");
scanf("%s", place);
Node *temp = head;
int dem = 0;
while (temp != NULL)
{
if (strcmp(temp->place, place) == 0)
{
if (dem > 0)
printf(", ");
printf("%d:%d", temp->h, temp->m);
dem++;
}
temp = temp->next;
}
if (dem == 0)
printf("Ban chua toi dia diem nay");
printf("\n");
}
void process4()
{
printf("Nhap gio can tim kiem: ");
scanf("%d", &h);
printf("Nhap phut can tim kiem: ");
scanf("%d", &m);
while (h < 0 || h > 23 || m < 0 || m > 59)
{
printf("Gio hoac phut khong hop le. Nhap lai: \n");
scanf("%d%d", &h, &m);
}
Node *temp = head;
int dem = 0;
while (temp != NULL)
{
if (temp->h == h && temp->m == m)
{
if (dem > 0)
printf(", ");
printf("%s", temp->place);
dem++;
}
temp = temp->next;
}
if (dem == 0)
printf("Ban chua toi gio nay");
printf("\n");
}
void process5()
{
printf("Nhap dia diem va thoi gian;\n");
scanf("%s %d %d", place, &h, &m);
while (h < 0 || h > 23 || m < 0 || m > 59)
{
printf("Gio hoac phut khong hop le. Nhap lai: \n");
scanf("%d", &h);
scanf("%d", &m);
}
Node *temp = head;
while (temp != NULL)
{
if (strcmp(temp->place, place) == 0)
{
if (temp->h > h)
{
printf("Ban co kha nang bi nhiem Covid, can phai khai bao y te ngay lap tuc\n");
break;
}
if (temp->h == h && temp->m >= m)
{
printf("Ban co kha nang bi nhiem Covid, can phai khai bao y te ngay lap tuc\n");
break;
}
printf("Ban khong co kha nang bi nhiem Covid\n");
}
temp = temp->next;
}
}
void freelinklist()
{
Node *temp = head;
while (temp != NULL)
{
head = head->next;
free(temp);
temp = head;
}
}
int main()
{
int x;
do
{
menu();
scanf("%d", &x);
if (!(1 <= x && x <= 6))
{
while (!(1 <= x && x <= 6))
{
printf("Nhap lai tinh nang: ");
scanf("%d", &x);
}
}
if (x == 1)
process1();
if (x == 2)
process2();
if (x == 3)
process3();
if (x == 4)
process4();
if (x == 5)
process5();
if (x == 6)
break;
} while ((1 <= x && x <= 6));
return 0;
}