欢迎光临散文网 会员登陆 & 注册

一道小学题,让数学大神三天三夜没睡着觉

2023-07-28 15:23 作者:阿扎尔很自信  | 我要投稿

class Peach{

public:  

int count = 0;  

int total = 0;  

int nucleus = 0;  

int money = 100;  

void BuyPeach(){    

money--;    count++;  

}  

void Eat(){    

count--;    nucleus++;    total++; 

 }  

void Exchange(){    

count += nucleus/2;    

nucleus -= nucleus/2*2;  

}  

void PrintArrtibute(){    

cout << "total is " << total << endl;    

cout << "money is " << money << endl;    

cout << "nucleus is " << nucleus << endl;    

cout << "count is " << count << endl;  

}

};

void TotalPeach(){  

Peach P;  

while(P.money>0){   

 P.BuyPeach();  

}  

while(P.count>0{    

P.Eat();    

if(P.nucleus>=2)P.Exchange();  

}  

P.PrintArrtibute();}

int main() {  

TotalPeach();  

return 0;

}

一道小学题,让数学大神三天三夜没睡着觉的评论 (共 条)

分享到微博请遵守国家法律