zoukankan      html  css  js  c++  java
  • The Coco-Cola Store

    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). The input terminates with n = 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个空瓶子可以换1瓶可乐,输入告诉你会有多少空瓶子,输出回答可以换到多少可乐

    方法一:

    使用模拟的方法做:

    代码:

    #include"iostream"
    using namespace std;
    const int maxn=110;
    int main()
    {
        int ca,n;
        while(cin>>n&&n)
        {
            ca=0;
            while(n>2)
            {
                n-=3;
                ca++;
                n+=1;
            }
            if(n==2)
            {
                ca++;
            }
            cout<<ca<<endl;
        }
    
    return 0;
    
    }

    方法二:
    其实只要输出每次的n/2就可以了

    代码


    #include"iostream"
    using namespace std;
    int main()
    {
       int n;
    	while(cin>>n&&n)
    	{
    		if(n!=2)
         cout<<n/2<<endl;
    		else
    			cout<<1<<endl;
    	}
    	return 0;
    }
  • 相关阅读:
    Qt中修改QtoolTip的样式
    字符编码笔记:ASCII、Unicode和UTF-8
    UML类图关系模式(C++代码说明)
    sql标签和include标签的使用
    mybatis动态SQL标签的用法
    <!CDATA[ ....... ]] > 用法详解
    Mybatis 中$与#的区别
    枚举
    ExtJs如何判断form表单是否被修改过详解
    Extjs二级联动combo省城市
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/4654770.html
Copyright © 2011-2022 走看看