zoukankan      html  css  js  c++  java
  • ACM第三次比赛UVA11877 The Coco-Cola Store

     
    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;
    }
  • 相关阅读:
    临时更换swap优先级
    设计一个百万级的消息推送系统----转
    使用apache cxf实现webservice服务
    如何成为一位「不那么差」的程序员---转
    轻量级web框架cicada----(转)
    shiro学习笔记
    java编程调试技巧
    zookeeper学习总结
    Kafka入门
    kafka 的经典教程
  • 原文地址:https://www.cnblogs.com/yilihua/p/4655698.html
Copyright © 2011-2022 走看看