-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasdstac.c
72 lines (63 loc) · 1.38 KB
/
asdstac.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
#include <stdio.h>
typedef unsigned char value_t;
typedef int boolean_t;
typedef int index_t;
#define STACK_SIZE 10
value_t t[STACK_SIZE] = { 0 };
index_t c = -1;
/*@
requires w>0;
requires c>=-1;
requires c<STACK_SIZE;
behavior limit_reached:
assumes c==(STACK_SIZE-1);
assigns \nothing;
ensures \result==0;
behavior regular:
assumes c<(STACK_SIZE-1);
assigns t[\old(c)], c;
ensures c==\old(c)+1;
ensures c<STACK_SIZE;
ensures \result==1;
ensures (\forall integer i; 0 <= i < STACK_SIZE ==> (i != \old(c) ==> \old(t[i])==t[i]));
complete behaviors limit_reached, regular;
disjoint behaviors limit_reached, regular;
*/
boolean_t push(value_t w) {
boolean_t res = c<(STACK_SIZE-1);
if(res) t[++c] = w;
return res;
}
/*@
requires c>=-1;
requires c<STACK_SIZE;
behavior empty:
assumes c==-1;
assigns \nothing;
ensures \result==0;
behavior regular:
assumes c>=0;
assigns c;
ensures \result==\old(t[\old(c)]);
ensures c==\old(c)-1;
complete behaviors empty, regular;
disjoint behaviors empty, regular;
*/
value_t pop() {
return c>=0 ? t[c--] : 0;
}
void print(value_t w);
void process(value_t w) {
if(w==0) print(pop());
else if(!push(w)) print(0);
}
void print(value_t w) {
printf("%u\n", w);
}
int main() {
int res;
value_t w;
while(res = scanf("%uhh", &w), res>0)
process(w);
return 0;
}