日期:2014-05-20 浏览次数:20751 次
int[] myStage = {4,4,3,3,4,4,3,3};
const int pastDays = 10;
int endDay = 0;
int stage = 0;
for (int offset = 0; offset < myStage.Length; offset++)
{
int startDay = endDay;
endDay = startDay + myStage[offset];
if (pastDays <= startDay || pastDays > endDay) continue;
stage = offset;
break;
}
Console.Write(stage);
int[] myStage = {4,4,3,3,4,4,3,3};
const int pastDays = 10;
int startDay =0;
int stage?=myStage.Select((x,i)=>new {x,i})
.Aggregate((x,y)=>
{
startDay+=x.x;
return startDay>=pastDays?x:y;
}).i;
Console.WriteLine(stage);
int[] myStage = { 4, 4, 1, 3, 4, 4, 3, 3 };
const int pastDays = 10;
int endDay = 0;
int stage = Array.FindIndex(myStage, o =>
{
int startDay = endDay;
endDay = startDay + o;
return (startDay < pastDays && pastDays <= endDay);
});