我也做出来了,不过不知道为什么会多1,所以减去了。- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int num,bottle,exchang,rest,last,flag;
- for(num=1;num<500;num++)
- {
- for(flag=0,bottle=num,exchang=bottle/3,rest=bottle%3;exchang/3!=0;)
- {
- last=exchang;
- bottle+=exchang;
- exchang=(exchang+rest)/3;
- rest=(last+rest)%3;
- if(exchang==0)
- bottle=bottle+rest;
- if(bottle>=500)
- {flag=1;break;}
- }
- if(flag==1)
- break;
- }
- printf("%d\n",num-1);
- system("pause");
- return 0;
- }
复制代码 |