2 u011120650 u011120650 于 2016.03.05 17:13 提问

ASP中一维数组如何判断是否存在重复项呢

请问一下,动态一维数组中如何判断数组中是否存在相同的值呢?
比如说动态数组A()
A(1)="A" A(2)="B" A(3)="A"
动态数组B()
B(1)=1 B(2)=2 B(3)=3

最后输出的是 A 4 B 2
就是A(1)+A(3) 相同的数组B()相加输出,不相同的直接输出B()对应的值

4个回答

showbo
showbo   Ds   Rxr 2016.03.05 20:13
已采纳
 a=split("A,B,A",",")
b=split("1,2,3",",")
for i = 0 to ubound(a)
    for j = i+1 to ubound(a)
        if a(i)<>"" and a(i)=a(j) then
            a(j)=""
            b(i) =cint( b(i)) + cint(b(j))
            b(j)=0
            exit for
        end if
    next
next

for i =0 to ubound(a)
  if a(i) <> "" then
    msgbox a(i) & " " & b(i)
  end if
next
caozhy
caozhy   Ds   Rxr 2016.03.05 18:09
 for i = 1 to ubound(a)
    for j = 1 to ubound(a)
        if a(i)=a(j) then
            b(i) = b(i) + b(j)
            b(j)=0:a(j)=""
            exit for
        end if
    next
next
for i = 1 to ubound(b)
if a(i) <> "" then
print a(i) & " " & b(i)
end if
next
u011120650
u011120650   2016.03.05 19:18

a(1)会重复。。。

u011120650
u011120650   2016.03.05 19:28

这样子改会不会更好点

  for i = 1 to ubound(a)
    for j = 1 to ubound(a)
        if i<>j and a(i)=a(j) then
            b(i) = b(i) + b(j)
            b(j)=0:a(j)=""
            exit for
        end if
    next
next
for i = 1 to ubound(b)
if a(i) <> "" then
print a(i) & " " & b(i)
end if
next
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!