标签:
//百鸡百钱 ,公鸡2文钱一只,母鸡1文钱一只,小鸡半文钱一只 //共有100文钱,如何在凑够100只鸡的情况下刚好花完100文钱 int count = 0; int bian = 0; for (int gong = 0; gong <= 50;gong++ ) { for (int mu = 0; mu <= 100;mu++ ) { for (int xiao = 0; xiao <= 200;xiao++ ) { bian++; if(gong+mu+xiao==100&&gong*2+mu+xiao*0.5==100) { count++; Console.WriteLine("第"+count+"种情况:公鸡:"+gong+"只,母鸡:"+mu+"只,小鸡:"+xiao +"只"); } } } } Console.WriteLine("共有"+count+"种买法。"); Console.WriteLine(bian); Console.ReadLine();
标签:
原文地址:http://www.cnblogs.com/fengsantianya/p/5459934.html