-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeup 4051.cpp
More file actions
104 lines (92 loc) · 1.77 KB
/
codeup 4051.cpp
File metadata and controls
104 lines (92 loc) · 1.77 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
#include <stdio.h>
#include <stdlib.h>
int result = 0;
int index = 0;
typedef struct node {
float time;
float atTime;
int check;
struct node* next;
}node;
typedef struct List {
struct node* head;
int count;
}List;
List* init() {
List* list = (List*)malloc(sizeof(List));
if (list == NULL) {
printf("err\n");
}
else {
list->head = NULL;
list->count = 0;
return list;
}
}
void insert(List* list, float time, float atTime) {
node* newNode = (node*)malloc(sizeof(node));
node* preNode = list->head;
newNode->time = time;
newNode->atTime = atTime;
newNode->check = 0;
newNode->next = NULL;
if (list->count == 0) {
newNode->next = newNode;
list->head = newNode;
index++;
}
else {
for (int i = 0; i < index; i++) {
preNode = preNode->next;
}
newNode->next = preNode->next;
preNode->next = newNode;
}
list->count++;
}
void check(List* list) {
float timecheck, count;
node* curNode = list->head;
if (list->count == 0) return;
if (list->head->check == 0) {
if (list->head->atTime <= list->head->time + 1) {
list->count--;
list->head = list->head->next;
free(curNode);
check(list);
}
else {
timecheck = list->head->atTime - (list->head->time + 1);
count = timecheck / 0.5;
if (count >= 8) {
result += 40000;
}
else {
result += count * 5000;
}
list->count--;
list->head = list->head->next;
free(curNode);
check(list);
}
}
}
int main() {
List* list = init();
float time, atTime;
for (int i = 0; i < 5; i++) {
float time, atTime;
scanf("%f %f", &time, &atTime);
insert(list, time, atTime);
}
check(list);
if (result >= 150000) {
result = result - (result * 0.05);
}
else if (result <= 50000) {
result = result + (result * 0.05);
}
printf("%d", result);
free(list);
return 0;
}