HDOJ 1056 HangOver

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


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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    int n_card;
    double card_length;
    // cout << "input the card length(one number by each line):" << endl;
    vector<double> 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<int> card;
    for(vector<double>::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<int>(n_card));
    }
 
    for(vector<int>::iterator card_it = card.begin(); card_it != card.end(); card_it++)
       cout << *card_it << " card(s)" << endl;
    return 0;
}

发布者

Tanky Woo

Tanky Woo,[个人主页:https://tankywoo.com] / [新博客:https://blog.tankywoo.com]

发表评论

电子邮件地址不会被公开。 必填项已用*标注