Blog·Tanky WooABOUTRSS

HDOJ 1056 HangOver

16 Aug 2010
这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。

题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1056


这题在POJ还AC了,结果在HDOJ就WA了。原因居然是HDOJ里这题不能用float,而要用double~~~无语。

#include 
#include 
using namespace std;

int main()
{
    int n_card;
    double card_length;
    // cout << "input the card length(one number by each line):" << endl;
    vector length;
    while((cin >> card_length))
    {
       if(card_length == 0.0 || card_length > 5.20 || card_length < 0.01)
          break;
       length.push_back(card_length);
    }
    vector card;
    for(vector::iterator iter = length.begin(); iter != length.end(); iter ++)
    {
        float total = 0.0;
        for(n_card = 2; total < *iter; n_card++)
            total += 1.0/n_card;
        n_card -= 2;
        card.push_back(static_cast(n_card));
    }

    for(vector::iterator card_it = card.begin(); card_it != card.end(); card_it++)
       cout << *card_it << " card(s)" << endl;
    return 0;
}