主题:hjdt
游戏之王
[专家分:540] 发布于 2007-11-05 18:57:00
随机产生20个字符串,长度在[10,30]之间,然后:
(1)按它们的大小进行分类,从小到大输出
(2)按它们的长度进行分类,从短到长输出
(3)按它们的长度进行分类,当长度相等的条件情况下,再按它们的大小进行分类
回复列表 (共7个回复)
沙发
网虫一号 [专家分:1230] 发布于 2007-11-05 18:58:00
CLS : DIM A$(20)
RANDOMIZE TIMER
FOR I = 1 TO 20
A = INT(RND * 21) + 10
FOR J = 1 TO A: A$(I) = A$(I) + CHR$(INT(95 * RND) + 32): NEXT J
NEXT I
FOR I = 1 TO 19: FOR J = I + 1 TO 20
IF A$(I)) > A$(J) THEN SWAP A$(I), A$(J)
NEXT J, I
FOR I = 1 TO 20: PRINT A$(I); " "; : X = X + 1
IF X MOD 2 = 0 THEN PRINT
NEXT I: PRINT : PRINT : PRINT
FOR I = 1 TO 19: FOR J = I + 1 TO 20
IF LEN(A$(I)) > LEN(A$(J)) THEN SWAP A$(I), A$(J)
IF LEN(A$(I)) = LEN(A$(J)) THEN
IF A$(I) > A$(J) THEN SWAP A$(I), A$(J)
END IF
NEXT J, I: X = 0
FOR I = 1 TO 20: PRINT A$(I); " "; : X = X + 1
IF X MOD 2 = 0 THEN PRINT
NEXT I: PRINT : PRINT : PRINT
END
板凳
小精灵1号 [专家分:1040] 发布于 2007-11-05 19:00:00
CLS : DIM A$(20)
RANDOMIZE TIMER
FOR I = 1 TO 20
A = INT(RND * 21) + 10
FOR J = 1 TO A: A$(I) = A$(I) + CHR$(INT(95 * RND) + 32): NEXT J
NEXT I
FOR I = 1 TO 19: FOR J = I + 1 TO 20
IF ASC(A$(I)) > ASC(A$(J)) THEN SWAP A$(I), A$(J)
NEXT J, I
FOR I = 1 TO 20: X = X + 1: PRINT A$(I); " ";
IF X MOD 2 = 0 THEN PRINT
NEXT I: PRINT : PRINT : PRINT
FOR I = 1 TO 19: FOR J = I + 1 TO 20
IF LEN(A$(I)) > LEN(A$(J)) THEN SWAP A$(I), A$(J)
IF LEN(A$(I)) = LEN(A$(J)) THEN
IF ASC(A$(I)) < ASC(A$(J)) THEN SWAP A$(I), A$(J)
END IF
NEXT J, I
FOR I = 1 TO 20: Y = Y + 1: PRINT A$(I); " ";
IF Y MOD 2 = 0 THEN PRINT
NEXT I
END
3 楼
我的电脑 [专家分:990] 发布于 2007-11-05 19:00:00
CLS
DIM A$(20),B(20),C$(20)
FOR I=1 TO 20:L=INT(RND*21)+10
FOR J=1 TO L:A$(I)=A$(I)+CHR$(INT(RND*95+32)):NEXT J
PRINT A$(I):B(I)=LEN(A$(I)):C$(I)=A$(I)
NEXT I
FOR I=1 TO 19:FOR J=I+1 TO 20
IF B(I)=B(J) THEN 10
IF B(I)>B(J) THEN SWAP B(I),B(J):SWAP A$(I),A$(J)
10 IF C$(I)>C$(J) THEN SWAP C$(I),C$(J)
NEXT J,I
FOR I=1 TO 20:PRINT C$(I):NEXT I:PRINT
FOR I=1 TO 20:PRINT A$(I):NEXT I
END
4 楼
网虫一号 [专家分:1230] 发布于 2007-11-05 19:01:00
忒简单!
5 楼
QB小猪 [专家分:1200] 发布于 2007-11-05 19:13:00
诶..................
6 楼
人才锐锐 [专家分:260] 发布于 2007-11-05 21:49:00
CLS
DIM A$(20),B(20),C$(20)
FOR I=1 TO 20:L=INT(RND*21)+10
FOR J=1 TO L:A$(I)=A$(I)+CHR$(INT(RND*95+32)):NEXT J
PRINT A$(I):B(I)=LEN(A$(I)):C$(I)=A$(I)
NEXT I
FOR I=1 TO 19:FOR J=I+1 TO 20
IF B(I)=B(J) THEN 10
IF B(I)>B(J) THEN SWAP B(I),B(J):SWAP A$(I),A$(J)
10 IF C$(I)>C$(J) THEN SWAP C$(I),C$(J)
NEXT J,I
FOR I=1 TO 20:PRINT C$(I):NEXT I:PRINT
FOR I=1 TO 20:PRINT A$(I):NEXT I
END
[em9][em9][em9]
7 楼
hxy_anhui [专家分:320] 发布于 2009-01-29 19:19:00
CLS
DIM A$(20)
FOR I = 1 TO 20
L = INT(RND * 20 + 1)
FOR J = 1 TO L
A$(I) = A$(I) + CHR$(64 + INT(RND * 26 + 1))
NEXT J
NEXT I
FOR I = 1 TO 19
FOR J = I + 1 TO 20
IF A$(I) > A$(J) THEN SWAP A$(I), A$(J)
NEXT J
NEXT I
FOR I = 1 TO 20
PRINT A$(I); " ";
NEXT I
PRINT
FOR I = 1 TO 19
FOR J = I + 1 TO 20
IF LEN(A$(I)) > LEN(A$(J)) THEN SWAP A$(I), A$(J)
NEXT J
NEXT I
FOR I = 1 TO 20
PRINT A$(I); " ";
NEXT I
PRINT
FOR I = 1 TO 19
FOR J = I + 1 TO 20
IF LEN(A$(I)) = LEN(A$(J)) THEN
IF A$(I) > A$(J) THEN SWAP A$(I), A$(J)
END IF
NEXT J
NEXT I
FOR I = 1 TO 20
PRINT A$(I); " ";
NEXT I
END
我来回复