-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqmax.c
69 lines (69 loc) · 1.11 KB
/
qmax.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
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main()
{
long n;
scanf("%ld\n", &n);
long *queue = malloc(n*sizeof(long));
long l = 4;
long start = 0;
long end1 = 0;
long end2 = n-1;
long qc = 0;
for (long i = 0; i < n; i++)
{
char s[25];
gets(s);
if (s[0] == 'D' && s[1] == 'E' && s[2] == 'Q')
{
if (end2 == n-1)
{
while (end1 != 0)
{
end1--;
long res = queue[end1];
queue[end2] = res;
end2--;
}
}
end2++;
long res = queue[end2];
printf("%ld\n", res);
}
else if (s[0] == 'E' && s[1] == 'N' && s[2] == 'D')
{
long h = strtol(s + 3, NULL, 10);
queue[end1] = h;
end1++;
}
else if (s[0] == 'M' && s[1] == 'A' && s[2] == 'X')
{
long mm = -2000000000;
for (long j = 0; j<end1; j++)
{
if (queue[j] > mm) mm = queue[j];
}
for (long j = n-1; j> end2; j--)
{
if (queue[j] > mm) mm = queue[j];
}
printf("%ld\n", mm);
}
else
{
if (end1 == 0 && end2== n-1)
{
printf("true\n");
}
else
{
printf("false\n");
}
}
}
free(queue);
return 0;
}