| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 626 人关注过本帖
标题:[求助]为什么输出正确的数字后,会自动输出一行 1 或 2 或其他数字?有图参 ...
只看楼主 加入收藏
吐歌
Rank: 2
等 级:论坛游民
帖 子:43
专家分:19
注 册:2014-10-19
结帖率:100%
收藏
已结贴  问题点数:5 回复次数:9 
[求助]为什么输出正确的数字后,会自动输出一行 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: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:2 
这个程序用来做什麽?

一片落叶掉进了回忆的流年。
2014-10-22 12:05
吐歌
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
soulmate1023
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:256
专家分:831
注 册:2014-9-23
收藏
得分:2 
回复 3 楼 吐歌
读了题了,还是没懂题目的意思?
2014-10-22 16:13
吐歌
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
soulmate1023
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:256
专家分:831
注 册:2014-9-23
收藏
得分:0 
回复 6 楼 吐歌
int candle(int n, int d){
if(n==d)  return (n+1);
else      return ((n/d)*d+candle(n-(n/d)*d+(n/d),d));
}
这是我写的一个递归函数,你可以参考。
2014-10-22 23:11
吐歌
Rank: 2
等 级:论坛游民
帖 子:43
专家分:19
注 册:2014-10-19
收藏
得分:0 
谢谢  我现在想知道为什么出现这种错误情况

||||||||||||^_^COMEONFORGOODLIFE^_^||||||||||||
2014-10-23 07:57
不是犀牛的牛
Rank: 2
等 级:论坛游民
帖 子:3
专家分:10
注 册:2014-10-23
收藏
得分:2 
回复 楼主 吐歌
int _tmain(int argc, _TCHAR* argv[])
{
    int a,b,c,d,x,f;
    scanf("%d%d",&a,&b);
    if(a<1|| a>2000 || b<2 || b>2000)
        printf("请重新输入a(1-2000),b(2-2000):");
    f  = 0;
    x = a;
    if(a>b)
    {
        for(;;)
        {
            c=x/b;
            d=x%b;
            x=c+d;
            f+=c;
            if(x < b)break;
        }
        printf("%d\n",f+a);
    }

    else if(a<b)
        printf("%d\n",a);
    else
        printf("%d\n",b+1);
    return 0;
}
这样应该就可以了
2014-10-23 18:38
gold615
Rank: 2
等 级:论坛游民
帖 子:54
专家分:75
注 册:2014-6-7
收藏
得分:2 
楼上说的对 之前楼主那个版本的 三个if之间不存在非此即彼的关系 都要执行的
2014-10-24 00:31
快速回复:[求助]为什么输出正确的数字后,会自动输出一行 1 或 2 或其他数字?有 ...
数据加载中...
 
   



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

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