香蕉视频app

Keep on going never give up.

Let's Go

C#【練習】啤酒兩元1瓶,四個瓶蓋換1瓶,兩個空瓶換1瓶,問10塊錢可以喝幾瓶?

C#Lonely2019-05-20 02:10:33207次3條

//啤酒兩元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

暗錨,解決錨點偏移

文章評論

    嘿,來試試登錄吧!