111,126
社区成员
发帖
与我相关
我的任务
分享
string strOutput = "";
const int man = 10;
const int dog = 15;
const double L = 30;
double Pass = (L / (man + dog)) * man; //算出第一次相遇小明走过的路程
for (int i = 1; Pass < L; i++)
{
strOutput = "第" + i + "次相遇到小明走了" + Pass + "公里";
Console.Write(strOutput+"\n");
if (strOutput.EndsWith("30公里"))
{
break;
}
else
{
Pass = Pass + 10 * ((L - Pass) / 25); //算出相遇后,小狗跑回到起点时,小明共走过的路程
Pass = Pass + ((L - Pass) / (man + dog)) * 10; //算出小狗跑回终点时,又跑向小明直到相遇时,小明共走过的路程
}
}
Console.ReadLine();
}
static void Main(string[] args)
{
int i = 0;
double sPeoson = 0;
double sSubPeoson = 30d / (10 + 15) * 10;
sPeoson += sSubPeoson;
Console.WriteLine("第" + (++i).ToString("d2") + "相遇:" + sSubPeoson.ToString("f14"));
while (sPeoson < 30d)
{
sSubPeoson = (30d - sPeoson) * 2 / (10d + 15) * 10;
if (sSubPeoson < Math.Pow(0.1, 14))
{
break;
}
sPeoson += sSubPeoson;
Console.WriteLine("第" + (++i).ToString("d2") + "相遇:" + sPeoson.ToString("f14"));
}
Console.ReadKey();
}
static void Main(string[] args)
{
int i = 0;
double sPeoson = 0;
double sSubPeoson = 30.0 / (10 + 15) * 10;
Console.WriteLine("第" + (++i).ToString("d2") + "相遇:" + sSubPeoson.ToString("f14"));
while (sPeoson < 30)
{
sSubPeoson = (30 - sPeoson) * 2 / (10 + 15) * 10;
if (sSubPeoson < Math.Pow(0.1, 14))
{
break;
}
sPeoson += sSubPeoson;
Console.WriteLine("第" + (++i).ToString("d2") + "相遇:" + sPeoson.ToString("f14"));
}
Console.ReadKey();
}