33,010
社区成员
发帖
与我相关
我的任务
分享
Result getResult(int day)
{
List<chiken> chikens = new List<chiken>() { chiken.get(10,1) };
List<Egg> eggs = new List<Egg>();
for (int i = 1; i <= day; i++)
{
List<chiken> tmpChiken=new List<chiken> ();
foreach (chiken c in chikens)
{
if (c.currentLife >= 4)
eggs.Add(Egg.get(4, 1));
else if (c.currentLife > c.Life)
tmpChiken.Add(c);
else
c.currentLife++;
}
remove<chiken>(chikens, tmpChiken);
List<Egg> tmpEgg = new List<Egg>();
foreach (Egg c in eggs)
{
if (c.currentLife > c.Life)
{
chikens.Add(chiken.get(10, 1));
tmpEgg.Add(c);
}
else
c.currentLife++;
}
remove<Egg>(eggs, tmpEgg);
}
return new Result() { chiken=chikens.Count , egg=eggs.Count };
}
void remove<T>(List<T> source, List<T> some)
{
foreach (var i in some)
source.Remove(i);
}
public class chiken
{
public static chiken get(int life, int currentlife)
{
return new chiken() { Life=life, currentLife =currentlife };
}
public int Life { set; get; }
public int currentLife { set; get; }
}
public class Egg
{
public static Egg get(int life, int currentlife)
{
return new Egg() { Life = life, currentLife = currentlife };
}
public int Life { set; get; }
public int currentLife { set; get; }
}
public class Result
{
public int chiken { set; get; }
public int egg { set; get; }
}