为什么不输出?

P1150 Peter 的烟

妖精の尾 @ 2017-09-08 17:45:29

#include<iostream>
using namespace std;
int main()
{
    int k,y,d,i,sum;
    cin>>y>>d;
    i=0;
    sum=0;
    while(y>=0);
    { 
                 y--;
                 sum++;
                 i++;
                 if(i=d) i=0;y++;     
    } 
    cout<<sum<<endl;
    return 0;
}

by 和泉正宗 @ 2017-09-08 17:46:30

这一行

 if(i=d) i=0;y++;

应该是i==d吧


by 和泉正宗 @ 2017-09-08 17:48:18

还有

while(y>=0);

分号应该去掉吧,不然会T


by 和泉正宗 @ 2017-09-08 17:52:22

然而你这个代码是错的233


by Peter_Z @ 2017-09-08 18:06:56

while(y>=0);

分号应去掉,否则当y>=0时会不断按照分号前括号后的内容(这里为空)循环,就会T


by 魔芋胶 @ 2017-09-29 11:09:00

# include <cstdio>
# include <iostream>
# include <cmath>
# include <string>
char a,b;
using namespace std;
int main()
{
    int k,y,i,sum;//y 开始的烟数;i 剩下烟头数 ;sum 吸烟计数器 
    cin>>y>>k;
    i=0;
    sum=0;
    while(y>0)
    {
                 y--;
                 sum++;
                 i++;
                 if(i==k) {i=0;y++;}
    } 
    cout<<sum;
    return 0;
}

|