The Coco-cola Store

Source: Internet
Author: User

Title Link: http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=23309

Main topic:

With 3 empty Coke bottles can be exchanged for a full bottle of Coke, with an n (1<=n<=100) empty Coke bottle, the most can drink to how many bottles of coke

It is important to note that if you have 10 empty bottles, first 3 bottles of Coke, after drinking 4 empty bottles, and then in exchange for 1 bottles, after drinking after 2 empty bottles, you can borrow an empty bottle, with the 3 empty bottles at this time for a bottle of Coke, drink the return bottle, so that 10 empty bottles can drink to 5 bottles of Coke.

Example:

Sample Input 3 Bayi 0 Sample Output 1 5 40 topic Analysis: According to the tip left 2 empty bottles can continue   In exchange for a bottle of Coke, you can use conditional discriminant statements (WHILE,IF, etc.), the number of empty bottles more than 1 can continue to redeem, at this time, there are two kinds of situations to discuss, whether the number of bottles is equal to 2, if, in exchange for a bottle of Coke after the end of the condition of discrimination, otherwise continue. Source:
1#include <iostream>2 using namespacestd;3 intMain ()4 {5     intN,k,count;6      while(cin>>n&&N)7{count=0;8k=0;9          while(n>1)Ten{if(n==2)//The bottle has 2 to borrow 1 drink 1 also 1 One{    ++count; A               Break; -         } -k=n/3; theCount+=k;//calculate the number of bottles that can be exchanged -n=n-2*k;//calculate the number of empty bottles left after redemption -         } -cout<<count<<Endl; +     } -     return 0; +}

The Coco-cola Store

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.