posts - 99,  comments - 8,  trackbacks - 0
一个水题可是错了好几次,原因就是在scanf    n   时输入的格式错了,应该是:%lf
//思路:首先是通过打表找到当长度取 0.01到5.20之间的数时,最多要多少张card,
//然后将张数存到length中用下表i表示张数 
#include <iostream>
#include <algorithm>
using namespace std;
#include <stdlib.h>

int main ()
{
    double length[300];
    memset ( length, 0, sizeof(length));
    for ( int i = 1; i <= 300; i ++)
    {
        for (int j = 1; j <= i; j ++)
        {
            length[i] += 1.0 / ( j + 1 );
        } 
        //printf ("%d %.2f\n", i, length[i]);
    }
    
    double n;
    while ( scanf ("%lf", &n) && n != 0.00 )
    {
          for ( int i = 1;i <= 300; i ++ )
          {
              if (  n <= length[i] )
              {
                    printf ("%d card(s)\n", i);
                    break;     
              } 
          }
    }
    system ("pause");
    return 0;
}
posted on 2010-09-07 21:04 雪黛依梦 阅读(317) 评论(0)  编辑 收藏 引用 所属分类: 简单题

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年8月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(4)

随笔分类

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜