Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为啥我这样做5.19求出272张卡#include<iostream> using namespace std; int hangover( double x) { int n=1; double cardlength,a,b; cardlength = 1.0 / (n + 1); for (cardlength;cardlength<x;cardlength += 1.0 / (n + 1)) { n++; } a = cardlength-1.0/(n+1); b = cardlength; if ((x - a) > (b - x)) { return n; } else return n-1; } int main() { double x; while (cin >> x&&x!=0.00) { int n=hangover(x); cout << n << " card(s)" << endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator