ACM第三次比赛UVA11877 The Coco-Cola Store
2015-07-17 21:11
288 查看
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瓶汽水,但同时也会多得到一个空瓶子。
程序代码:
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; }
相关文章推荐
- CSU 1160(进制问题)
- 阿里电话面试总结
- isalnum
- Android IOS WebRTC 音视频开发总结(三五)-- chatroulette介绍
- 每天一个Linux命令-5(tail)
- 我以前从来不会多想
- poj 2828 Buy Tickets(线段树)
- 线程安全函数是什么
- POJ 2923 状压好题
- CSU 1160 A(Contest #3)
- 每天一个linux命令(4):mkdir命令
- hdu1003(水dp)
- ASP.NET 3.5 MVC框架深度解析
- OC基础--@property修饰符
- ArcGIS中各种合并要素(Union、Merge、Append、Dissolve)的异同点分析 转载
- (简单) POJ 2492 A Bug's Life,二分染色。
- 【RQNOJ356】myt的格斗
- 小晴天老师系列——可恶的墨水瓶(floodfill)
- javaweb新建helloworld项目
- Java_LIST使用方法和四种遍历arrayList方法