水题编号 | 水题编号 | 水题编号 | 水题编号 | 水题编号 |
---|---|---|---|---|
1000 | 1003 | 1004 | 1005 |
// 1003 应该有改进空间
// 1、寻找分数求和公式;
// 2、减少内部循环求和中除法的次数:存下前面已经计算过的值,
// 只用计算后续数字,或者直接查找已经计算过的数字。
#include <iostream>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv) {
int n;
double len;
double result = 0.0;
do{
scanf("%lf",&len);
if(len==0.00 || len>5.20){
break;
}
result = 0.0;
for(n = 2;;n++){
result += 1.0/n;
if(result >= len ){
break;
}
}
printf("%d card(s)\n",n-1);
}while(1);
}