ZOJ1005

题目大意:这是一个倒水的问题,有A,B两个杯子,现要你通过往A,B杯子中倒水,然后得到题目中所需要的水量,注意:题目要求的水量最后是放在B杯子中的,还有倒水的解不唯一;

 1 #include<stdio.h>
2 int main()
3 {
4 int a,b,n,temp1,temp2;
5 while(scanf("%d%d%d",&a,&b,&n)!=EOF)
6 {
7 temp1=temp2=0;
8 while(1)
9 {
10 if(temp1==0)
11 {
12 printf("fill A\n");
13 temp1+=a;
14 }
15 if(temp2!=b)
16 {
17 printf("pour A B\n");
18 if(temp2+temp1>=b)
19 {
20 temp1=temp2+temp1-b;
21 temp2=b;
22 }
23 else
24 {
25 temp2=temp2+temp1;
26 temp1=0;
27 }
28 if(temp2==n)
29 break;
30 }
31 else
32 {
33 printf("empty B\n");
34 temp2=0;
35 }
36 }
37 printf("success\n");
38 }
39 return 0;
40 }

 

posted @ 2011-12-13 22:08  弄月吟风  阅读(171)  评论(0编辑  收藏  举报