注册 登录
编程论坛 ASP技术论坛

就是数一堆数字,我想知道其中一个排第几

liuzhibiao2632 发布于 2008-11-04 11:13, 1170 次点击
如:7,8,9,10,11,15,25,81,1,...怎么查11在里面按大到小排在第几位呢?
高手救救我啊...在线等的啊...
5 回复
#2
yms1232008-11-04 12:26
如果是按,号分割用Split函数就能解决这个问题
<%
Function ReLocation(Str,Num)
   Dim tAry,i,Loc
   Loc=-1
   tAry=Split(Str,",")
   For i=0 To Ubound(tAry)
       If CInt(tAry(i))=Num Then
          Loc=i
          Exit For
       End IF
   Next
   ReLocation=Loc
End Function
Dim tStr
tStr="7,8,9,10,11,15,25,81,1"
Respons.Write "字符串'"&tStr&"'中11在第"&ReLocation(tStr,11)&"位"
%>
#3
tianyu1232008-11-04 15:34
做个参考
<%
function ss(str,num)
str=str
num=num
s1=1
s=split(str,",")
for i=0 to ubound(s)-1
    for j=i+1 to ubound(s)
        if cint(s(i))<cint(s(j)) then
           temp=s(i)
           s(i)=s(j)
           s(j)=temp
        end if
    next
next
for k=0 to ubound(s)
    if s(k)<>cstr(num) then
       s1=s1+1
    else
        exit for
    end if
next
ss=s1
end function
dim str
str="7,8,9,10,11,15,25,81,1"
response.write"11 在数字 "&str&" 中按大到小排在第<font color=red>"&ss(str,11)

&"</font>位"
%>

[[it] 本帖最后由 tianyu123 于 2008-11-4 15:35 编辑 [/it]]
#4
ak42d2008-11-04 15:39
高手!~~~

我看不懂   厲害啊
#5
multiple19022008-11-04 22:55
用快排吧……
#6
liuzhibiao26322008-11-05 08:46
谢了..
1