| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 500 人关注过本帖
标题:筛选问题
只看楼主 加入收藏
hexi171
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-6-4
收藏
 问题点数:0 回复次数:4 
筛选问题
请问各位该怎么编程实现下面的过程:
比赛规则:去掉一个最高分和一个最低分,求出剩下得分的平均值
搜索更多相关主题的帖子: 筛选 
2007-06-04 18:02
ouzhiguang
Rank: 1
来 自:湖南长沙
等 级:新手上路
威 望:1
帖 子:240
专家分:0
注 册:2007-5-18
收藏
得分:0 

排序啊,找到一组数的最大值和最小值然后把剩下的平均啊

Private Sub Command1_Click()
Dim a(1 To 5) As Integer
For i = 1 To 5
a(i) = InputBox("N")
Next i
Dim max, min, avsum As Single
max = a(1)
min = a(1)
For i = 1 To 5
If max <= a(i) Then
max = a(i)

End If
If min >= a(i) Then
min = a(i)
End If
Next i
For i = 1 To 5
Sum = Sum + a(i)
Next i
avsum = (Sum - max - min) / 3
Print a(1); a(2); a(3); a(4); a(5)
Print max; min; Sum; avsum


End Sub

2007-06-04 21:51
缘子弹
Rank: 1
等 级:新手上路
帖 子:184
专家分:0
注 册:2007-4-5
收藏
得分:0 

楼上算法不错,我稍微拓展了一下:
Private Sub Command1_Click()
Dim a() As Integer,n as integer,i as integer,sum as long
n=val(inputbox("请输入评委的个数"))
Redim a(1 to n)
For i = 1 To n
a(i) = InputBox("请输入第" & i & "个分数")
Next i
Dim max, min, avsum As Single
max = a(1)
min = a(1)
For i = 1 To n
If max <= a(i) Then
max = a(i)
End If

If min >= a(i) Then
min = a(i)
End If

Next i

For i = 1 To n
sum = sum + a(i)
Next i
avsum = (sum - max - min) / (n-2)
for i=1 to n
print a(i)
next i
Print "Max=" & max;"Min=" & min;"Sun=" & sum; "Avsum=" & avsum

End Sub


2007-06-24 16:29
slore
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1108
专家分:0
注 册:2005-7-1
收藏
得分:0 

这个要求不需要多浪费次循环排序。。。
Private Sub Command1_Click()
Dim a() As Integer, n As Integer, i As Integer
n = Val(InputBox("请输入评委的个数"))
ReDim a(1 To n)
For i = 1 To n
a(i) = InputBox("请输入第" & i & "个分数")
Next i

Dim NumMax!, NumMin!, NumSum!, AveSum As Single
NumMin = a(1): NumMax = a(1): NumSum = a(1)
For i = 2 To n
If a(i) > NumMax Then NumMax = a(i)
If a(i) < NumMin Then NumMin = a(i)
NumSum = NumSum + a(i)
Next i
AveSum = (NumSum - NumMax - NumMin) / (n - 2)

For i = 1 To n
Print a(i)
Next i

Print "Max=" & NumMax; " Min=" & NumMin; " Sum=" & NumSum; " AveSum=" & AveSum
End Sub

[此贴子已经被作者于2007-6-24 18:35:34编辑过]


快上课了……
2007-06-24 18:34
缘子弹
Rank: 1
等 级:新手上路
帖 子:184
专家分:0
注 册:2007-4-5
收藏
得分:0 

这道题还应该考虑当评委数为2的情况怎么处理!~


2007-06-24 19:16
快速回复:筛选问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016957 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved