In this paper, we describe the problem of C # algorithm design about 1000 bottles of water. Share to everyone for your reference. Specific as follows:
The topics are as follows:
Suppose there are n bottles of water (of course n>0 bar)
An empty bottle that you can get after every bottle you drink.
And every 3 empty bottles can change 1 bottles of water, drink and then get an empty bottle,
How many bottles of water can I drink in total, and how many empty bottles are left at the end?
The code is as follows:
private int water (int n, int emptyqty) {Console.WriteLine ("Drink" + N + "bottle water, Multi" + Emptyqty + "empty bottle."); if (n + emptyqty < 3 )//If you finish drinking water + empty bottle is not 3, then drink the {Console.WriteLine ("many" + (n + emptyqty) + "Empty Bottle"); return n;} int a = (n + emptyqty)/3; Drank the convertible a bottle of water int b = (n + emptyqty)% 3; More than a few empty bottles return n + water (A, b);}
Assuming the first 1000 bottles, call the method
int sum = water (1000,0); Console.WriteLine ("Drink" + sum + "bottle of Water");
I hope this article is helpful to everyone's C # programming.
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
C # algorithm design about 1000 bottles of water problem
This address: http://www.paobuke.com/develop/c-develop/pbk23150.html
Related content development--corporate transfer to User C # using performance counters to monitor network status WPF Bullet Definition window methods WinForm Implementation Control Input Method
C # Implementing Windows Form Restriction text box Input Method C # methods to implement Windows Form Countdown Method C # calls an Oracle stored procedure in ASP. NET MVC 5 uses X.PAGEDLIST.MVC for a paging tutorial ( PAGEDLIST.MVC)
C # algorithm design about 1000 bottles of water problem