我正在Visual Studio Express 2012中完成一项任务,挑战要求我创建一个应用程序,允许用户输入三个跑步者的名字和完成时间。我正在为第一,第二和第三名获胜者制作If ... Then ... Else部分的流程图。任何人都可以帮助我或引导我在正确的方向上创建条件语句部分吗?
这就是我所拥有的:
If intRunner1 < intRunner2 And intRunner1 < intRunner3 Then
lblDisplay.Text = "First Place"
End If
If intRunner2 < intRunner1 And intRunner2 < intRunner3 Then
lblDisplay.Text = "First Place"
End If
If intRunner3 < intRunner1 And intRunner3 < intRunner2 Then
lblDisplay.Text = "First Place"
我也有:
If intFinish1 < intFinish2 Then
If intFinish1 < intFinish3 Then
lblFirstPlace.Text = "Runner 1 finished in first place."
Else
lblSecondPlace.Text = "Runner 1 finished in second place."
Else
If intFinish1 < intFinish3 Then
lblFirstPlace.Text = "Runner 1 finished in second place."
Else
lblThirdPlace.Text = "Runner 1 finished in thirdplace"
End If
End If
答案 0 :(得分:0)
你应该制作大小等于跑步者数量的2d数组。在第一维中插入跑步者的名字,在第二维中插入跑步者的时间。然后在第二维上对此数组进行排序以获得获胜者。由于范围非常小并且仅用于演示,您可以使用if then else条件来检查排序。
只需按正确的顺序在2d数组中插入跑步者,然后在插入所有数据后输出数组以获得获胜者名单。
例如第二种方法的伪代码:
create 2d array A
repeat for each runner
input runner name
input runner time
if A has runners
check runner against each runner in A
insert runner at the correct position
else
insert runner in A
end repeat
Take A if A beats B (then he is definately second or first) if A beats C (then he is definately first) A is first if B beats C B is second, C is third else C is second, B is third else A is second if B beats C B is first, C is third else C is first, B is third else ... if A beat C.... and so on
预测此项以检查每种可能的情况。