POJ - 1003

#include 

float GetLength(int card_num) {
    float   len = 0.0;
    for (int i = 1; i <= card_num; i++) {
        float incr = 1.0 / (1 + i);
        len += incr;
    }
    return len;
}

int GetCardNum(float length) {
    int CardNum = 1;
    while (GetLength(CardNum) < length) {
        CardNum++;
    }
    return CardNum;
}

int main() {
    float c;
    while (scanf("%f",&c) && c!=0) {
        printf("%0d card(s)", GetCardNum(c));
    }
}

你可能感兴趣的:(POJ - 1003)