OJ百练1003:Hangover

#include <iostream>
using namespace std;
int cards(float lenth)
{
    int num = 1;
    float currentLen = 0.5f;
    while(lenth >= currentLen)
    {
        ++num;
        currentLen += 1.0 / (num + 1);
    }
    return num;
}
int main()
{
    float len;
    while(cin >> len && len != 0.00)
    {
        cout << cards(len) << " " << "card(s)" << endl;;
    }
    return 0;
}

你可能感兴趣的:(OJ百练1003:Hangover)