Keep on going never give up.

Let's Go

C#【练习】啤酒两元1瓶,四个瓶盖换1瓶,两个空瓶换1瓶,问10块钱可以喝几瓶?

C#Lonely2019-05-20 02:10:33160次0条

//啤酒两元1瓶,四个瓶盖换1瓶,两个空瓶换1瓶,问10块钱可以喝几瓶?
int pj; //啤酒
int pg; //瓶盖
int kp; //空瓶            
int hpj; //换的啤酒
int money = 10; //金钱
pj = money / 2; //啤酒=10/2,啤酒为5瓶
pg = pj; //瓶盖5个
kp = pj; //空瓶5个
while (pg / 4 != 0 || kp / 2 != 0)
{
    hpj = (pg / 4) + (kp / 2);
    pg = (pg % 4) + hpj;
    kp = (kp % 2) + hpj;
    pj += hpj;
}
Console.WriteLine("啤酒两元1瓶,四个瓶盖换1瓶,两个空瓶换1瓶,问10块钱可以喝:{0}瓶", pj);
Console.ReadKey();

image.png

暗锚,解决锚点偏移

文章评论

    嘿,来试试登录吧!