-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathZOJ1005(AC).cpp
108 lines (91 loc) · 1.16 KB
/
ZOJ1005(AC).cpp
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
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
using namespace std;
void swap(int *a,int *b)
{
int t;
t = *a;
*a = *b;
*b = t;
}
void swap(char *a, char *b)
{
char t;
t = *a;
*a = *b;
*b = t;
}
int main()
{
int ca;
int cb;
int n;
char na;
char nb;
int a;
int b;
int success;
while(true)
{
if(scanf("%d%d%d", &ca, &cb, &n) != 3)
{
break;
}
na = 'A';
nb = 'B';
if(ca > cb)
{
swap(&ca, &cb);
swap(&na, &nb);
}
a = 0;
b = 0;
success = 0;
while(success == 0)
{
//Fill b
b = cb;
printf("fill %c\n", nb);
if(a == n || b == n)
{
success = 1;
break;
}
while(success == 0 && b >= ca)
{
//Pour b into a
b = b - (ca - a);
a = ca;
printf("pour %c %c\n", nb, na);
if(a == n || b == n)
{
success = 1;
break;
}
//Empty a
a = 0;
printf("empty %c\n", na);
if(a == n || b == n)
{
success = 1;
break;
}
}
if(success == 1)
{
break;
}
//Pour b into a
a = b;
b = 0;
printf("pour %c %c\n", nb, na);
if(a == n || b == n)
{
success = 1;
break;
}
}
printf("success\n");
}
return 0;
}