Topic description
Is there a Warren?
Yes, the little race is.
After rigorous calculation, the race bought a stock, he knew that from the day he bought the stock, the stock will have the following changes: The first day unchanged, after a day, fall one day, up two days, a day, up three days, fall one day ... So
For the convenience of calculation, assuming that each rise and fall are 1, the initial price of the stock is also 1, please calculate the first n days to buy a stock value of how much money per share.
Input
Input includes multiple sets of data;
Enter a n,1<=n<=10^9 per line.
Sample input
1
2
3
4
5
Output
Please output his stock per share how much money, for each set of data, output one line.
Sample output
1
2
1
2
3
water problem, the idea is that every day is to judge whether to jump out, in the while loop inside, divided into two parts, some used to rise, part of the fall, rose more times than the last time
#include <iostream> using namespace std; int main () {int n;
while (cin>>n) {int sums = 1;
int flag = 1;
int t=1;//record number of days int day=1;
int tt = 1;//How many days while (true) {if (day==n) break;
if (flag==1) {//rose for (int i = 0; i < TT; ++i) {sums++;
day++;
if (day==n) break;
} else tt++;
if (day==n) break;
if (flag==-1) {sums--;
day++;
} flag*=-1;
} cout<<sums<<endl;
return 0; }