试算了一下,结果不知对否?
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
程序代码:
USE 原表 IN 0
n = FCOUNT("原表")
IF !FILE("组合表.dbf")
DIMENSION ai[2,n]
cmd = ""
FOR i = 1 TO n
ai[1,i] = 100 + i
ai[2,i] = 200 + i
cmd = cmd + ",列" + TRANSFORM(i) + " N(4,0)"
ENDFOR
EXECSCRIPT("CREATE TABLE 组合表 (" + SUBSTR(cmd, 2) + ")")
SELECT 组合表
DO WHILE my组合表()
ENDDO
ELSE
USE 组合表 IN 0
ENDIF
cmd = ""
FOR i = 1 TO n
cmd = cmd + ",列" + TRANSFORM(i) + " N(4,0)"
ENDFOR
EXECSCRIPT("CREATE CURSOR 结果表 (" + SUBSTR(cmd, 2) + ")")
SELECT 原表
SCAN
SELECT 原表
COPY TO ARRAY a原表 NEXT 2
SELECT "组合表"
SCAN
SELECT "组合表"
COPY TO ARRAY a组合表 NEXT 2
tj1 = 0
tj2 = 0
FOR i = 1 TO n
i1 = IIF(a组合表[1, i] < 200, 1, 2)
j1 = a组合表[1, i] - IIF(a组合表[1, i] < 200, 100, 200)
tj1 = tj1 + a原表[i1, j1]
tj2 = tj2 + a原表[i1, j1]^2
ENDFOR
IF (tj1 == 294) AND (tj2 == 9506)
FOR i = 1 TO n
i1 = IIF(a组合表[1, i] < 200, 1, 2)
i2 = IIF(a组合表[2, i] < 200, 1, 2)
j1 = a组合表[1, i] - IIF(a组合表[1, i] < 200, 100, 200)
j2 = a组合表[2, i] - IIF(a组合表[2, i] < 200, 100, 200)
a组合表[1, i] = a原表[i1, j1]
a组合表[2, i] = a原表[i2, j2]
ENDFOR
SELECT 结果表
APPEND FROM ARRAY a组合表
ENDIF
ENDSCAN
ENDSCAN
** * 校对结果
** SELECT 结果表
** GO TOP
** SKIP
** DO WHILE !EOF()
** IF (列1+列2+列3+列4+列5+列6+列7+列8+列9+列10+列11+列12 == 294) AND;
** (列1^2+列2^2+列3^2+列4^2+列5^2+列6^2+列7^2+列8^2+列9^2+列10^2+列11^2+列12^2 == 9506)
** ELSE
** ? RECNO()
** ENDIF
** SKIP 2
** ENDDO
SELECT 结果表
GO TOP
BROWSE
CLOSE DATABASES ALL
RETURN
FUNCTION my组合表()
APPEND FROM ARRAY ai
FOR i = 1 TO n
IF ai[2,i] > 200
EXIT
ENDIF
ENDFOR
IF i > n
RETURN .F.
ENDIF
tmp = ai[2,i]
ai[2,i] = ai[1,i]
ai[1,i] = tmp
FOR j = 1 TO i-1
tmp = ai[1,j]
ai[1,j] = ai[2,j]
ai[2,j] = tmp
ENDFOR
RETURN .T.
ENDFUNC
[此贴子已经被作者于2016-4-12 08:10编辑过]