码迷,mamicode.com
首页 > 其他好文 > 详细

ACM第三次比赛UVA11877 The Coco-Cola Store

时间:2015-07-17 22:42:09      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

 
Once upon a time, there is a special coco-cola store. If you return three empty bottles to the shop,
you’ll get a full bottle of coco-cola to drink. If you have n empty bottles right in your hand, how many
full bottles of coco-cola can you drink?
Input
There will be at most 10 test cases, each containing a single line with an integer
n
(1<=n<=100). Theinput terminates withn= 0, which should not be processed.
Output
For each test case, print the number of full bottles of coco-cola that you can drink.
Spoiler
Let me tell you how to drink 5 full bottles with 10 empty bottles: get 3 full bottles with 9 empty
bottles, drink them to get 3 empty bottles, and again get a full bottle from them. Now you have 2
empty bottles.
Borrow another empty bottle from the shop
, then get another full bottle. Drink it, and
finally return this empty bottle to the shop!
Sample Input
3
10
81
0
Sample Output
1
5
40

程序分析:此题的大概意思就是3空汽水瓶子可以换一瓶汽水,但是值得注意的就是每3个空瓶子得1瓶汽水,但同时也会多得到一个空瓶子。

程序代码:

#include<cstdio>
#include<iostream>
using namespace std;
int main()
{int T,n,i=0;
while(scanf("%d",&n)==1&&n)
{
    if(n<3)
{cout<<0<<endl;
continue;
}

while(n>0)
{n-=3;
i++;
n++;
}
i+=n;
cout<<i<<endl;
i=0;
}
return 0;
}

 

ACM第三次比赛UVA11877 The Coco-Cola Store

标签:

原文地址:http://www.cnblogs.com/yilihua/p/4655698.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!