| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 626 人关注过本帖
标题:[求助]为什么输出正确的数字后,会自动输出一行 1 或 2 或其他数字?有图参 ...
取消只看楼主 加入收藏
吐歌
Rank: 2
等 级:论坛游民
帖 子:43
专家分:19
注 册:2014-10-19
结帖率:100%
收藏
已结贴  问题点数:5 回复次数:4 
[求助]为什么输出正确的数字后,会自动输出一行 1 或 2 或其他数字?有图参考
程序代码:
int main()
{
    int a,b,c,d,x,f;
    while(scanf("%d%d",&a,&b)!=-1)
    {
        f=0;
        x=a;
        if(a>b)
        {
            for(;;)
           {
               c=a/b;
               d=a%b;
               a=c+d;
               f+=c;
               if(a<b)
                {printf("%d\n",f+x);
                 break;}
           }
        }

        if(a<b)
            printf("%d\n",a);
        if(a==b)
            printf("%d\n",b+1);

    } return 0;
}
2014-10-22 09:47
吐歌
Rank: 2
等 级:论坛游民
帖 子:43
专家分:19
注 册:2014-10-19
收藏
得分:0 
蜡烛问题   原题如下
ACMer the Programmer loves romance, so this year he decided to illuminate his room with candles.
ACMer has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. ACMer is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now ACMer wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
Input
Input
There are more test cases. The single line contains two integers, a and b (1≤a≤1000; 2≤b≤1000).
Output
Print a single integer — the number of hours Vasily can light up the room for.
Sample Input
4 2
Sample Output
7

||||||||||||^_^COMEONFORGOODLIFE^_^||||||||||||
2014-10-22 13:30
吐歌
Rank: 2
等 级:论坛游民
帖 子:43
专家分:19
注 册:2014-10-19
收藏
得分:0 
大体意思是这样:
       输入第一个数代表现在有多少支蜡烛,每支蜡烛可燃烧一小时,输入的第二个数代表新蜡烛燃烧完后需要几支蜡烛的残余物可组成一个新的蜡烛,所组成的新蜡烛同样可燃烧一小时。需要输出的是这些蜡烛总共可燃烧多少个小时!

||||||||||||^_^COMEONFORGOODLIFE^_^||||||||||||
2014-10-22 21:57
吐歌
Rank: 2
等 级:论坛游民
帖 子:43
专家分:19
注 册:2014-10-19
收藏
得分:0 
求大神帮忙  万分感谢

||||||||||||^_^COMEONFORGOODLIFE^_^||||||||||||
2014-10-22 22:39
吐歌
Rank: 2
等 级:论坛游民
帖 子:43
专家分:19
注 册:2014-10-19
收藏
得分:0 
谢谢  我现在想知道为什么出现这种错误情况

||||||||||||^_^COMEONFORGOODLIFE^_^||||||||||||
2014-10-23 07:57
快速回复:[求助]为什么输出正确的数字后,会自动输出一行 1 或 2 或其他数字?有 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013195 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved