-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1005.cpp
93 lines (92 loc) · 1.32 KB
/
1005.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
#include <iostream.h>
void main ()
{
int Ca,Cb,n;
int a,b,step1,step2;
while (cin>>Ca>>Cb>>n)
{
a=0;b=0;step1=0;step2=0;
while (1)
{
if (a==0)
{
a=Ca;step1++;
}
if (b==n) break;
if (Cb-b>a) {b+=a;a=0;}
else {a-=(Cb-b);b=Cb;}
step1++;
if (b==n) break;
if (b==Cb)
{
b=0;step1++;
}
if (b==n) break;
}
a=0;b=0;
while (1)
{
if (b==0)
{
b=Cb;step2++;
}
if (b==n) break;
if (Ca-a>b) {a+=b;b=0;}
else {b-=(Ca-a);a=Ca;}
step2++;
if (b==n) break;
if (a==Ca)
{
a=0;step2++;
}
if (b==n) break;
}
a=0;b=0;
if (step1<step2)
{
while (1)
{
if (a==0)
{
a=Ca;step1++;
cout<<"fill A"<<endl;
}
if (b==n) break;
if (Cb-b>a) {b+=a;a=0;}
else {a-=(Cb-b);b=Cb;}
cout<<"pour A B"<<endl;step1++;
if (b==n) break;
if (b==Cb)
{
b=0;step1++;
cout<<"empty B"<<endl;
}
if (b==n) break;
}
cout<<"success"<<endl;
}
else
{
while (1)
{
if (b==0)
{
b=Cb;step2++;
cout<<"fill B"<<endl;
}
if (b==n) break;
if (Ca-a>b) {a+=b;b=0;}
else {b-=(Ca-a);a=Ca;}
cout<<"pour B A"<<endl;step2++;
if (b==n) break;
if (a==Ca)
{
a=0;step2++;
cout<<"empty A"<<endl;
}
if (b==n) break;
}
cout<<"success"<<endl;
}
}
}