主题:加分!(30)
游戏之王
[专家分:540] 发布于 2007-08-17 10:52:00
棋子问题:有黑白棋子各有N个(分别用*和0代替),按下图方式排列:
* * * . . . * * * 0 0 0 . . . 0 0 0
N个黑棋 N个白棋
允许将相邻两个棋子互换位置,最后使队形成黑白交替排列,如何编程实现该操作。
回复列表 (共9个回复)
沙发
网虫一号 [专家分:1230] 发布于 2007-08-17 10:53:00
CLS
INPUT N
DIM A$(N * 2 + 1): PRINT " ";
FOR I = 1 TO N: A$(I) = "*": PRINT A$(I); : NEXT I
FOR I = N + 1 TO N * 2: A$(I) = "0": PRINT A$(I); : NEXT I: PRINT
FOR I = 1 TO N - 1
FOR J = 1 TO N * 2
IF A$(J) = "*" AND A$(J + 1) = "0" THEN SWAP A$(J), A$(J + 1): J = J + 1
NEXT J: PRINT LTRIM$(STR$(I)); ":";
FOR J = 1 TO N * 2: PRINT A$(J); : NEXT J: PRINT
NEXT I
END
板凳
wzc1996 [专家分:1680] 发布于 2007-08-17 12:18:00
CLS
INPUT N
DIM A$(N * 2 + 1): PRINT " ";
FOR A = 1 TO N: A$(A) = "*": PRINT A$(A); : NEXT A
FOR A = N + 1 TO N * 2: A$(A) = "0": PRINT A$(A); : NEXT A: PRINT
FOR A = 1 TO N - 1
FOR B = 1 TO N * 2
IF A$(B) = "*" AND A$(B + 1) = "0" THEN SWAP A$(B), A$(B + 1): B = B + 1
NEXT B: PRINT LTRAM$(STR$(A)); ":";
FOR B = 1 TO N * 2: PRINT A$(B); : NEXT B: PRINT
NEXT A
END
3 楼
Matodied [专家分:7560] 发布于 2007-08-17 13:56:00
CLS
INPUT n
DIM a$(n * 2)
FOR i = 1 TO n * 2
IF i <= n THEN a$(i) = "*" ELSE a$(i) = "0"
PRINT a$(i);
NEXT i
IF n = 1 THEN END
IF n MOD 2 = 0 THEN s = 2 ELSE s = 4
PRINT : m = -1
DO
m = m + 2: i = n: j = n
DO
SWAP a$(i), a$(i + 1)
FOR k = 1 TO n * 2: PRINT a$(k); : NEXT k: PRINT
IF i <> j THEN
SWAP a$(j), a$(j + 1)
FOR k = 1 TO n * 2: PRINT a$(k); : NEXT k: PRINT
END IF
i = i - 1: j = j + 1
LOOP UNTIL i = m
LOOP UNTIL j - i = s
END
4 楼
小精灵1号 [专家分:1040] 发布于 2007-08-18 08:17:00
CLS
INPUT N
DIM A$(N * 2 + 1)
PRINT " "; STRING$(N, "*"); : PRINT STRING$(N, "0")
FOR I = 1 TO N: A$(I) = "*": NEXT I
FOR I = N + 1 TO N * 2: A$(I) = "0": NEXT I
FOR I = 1 TO N - 1
FOR J = 1 TO N * 2
IF A$(J) = "*" AND A$(J + 1) = "0" THEN SWAP A$(J), A$(J + 1): J = J + 1
NEXT J: PRINT LTRIM$(STR$(I)); ":";
FOR J = 1 TO N * 2: PRINT A$(J); : NEXT J
PRINT : NEXT I
END
5 楼
游戏之王 [专家分:540] 发布于 2007-08-18 08:17:00
wzc1996你真无耻,竟然把人家的题目复制去,就把变量改一下!无耻!无耻!!超级无耻!!!哼!哼!!哼!!!
6 楼
QB小猪 [专家分:1200] 发布于 2007-08-18 08:17:00
cls
input n:dim a(2*n)
for i=1 to n:a(i)=-1:next i
for i=n+1 to 2*n:a(i)=0:next i
for i=n to 2 step -1:for j=1 to 2*n
if a(j)=-1 and a(j+1)=0 then swap a(j),a(j+1):j=j+1
next j
for k=1 to 2*n
if a(k)=-1 then ?"*"; else ?"0";
next k:?
next i
for i=1 to 2*n
if a(i)=-1 then ?"*"; else ?"0";
next i
end
7 楼
Matodied [专家分:7560] 发布于 2007-08-18 15:15:00
为什么不给我加分?我又不是抄的。
8 楼
wzc1996 [专家分:1680] 发布于 2007-08-18 19:46:00
[quote]wzc1996你真无耻,竟然把人家的题目复制去,就把变量改一下!无耻!无耻!!超级无耻!!!哼!哼!!哼!!![/quote]
那我就揭穿你。QB小猪、我的电脑、小精灵1号、网虫1号应该都是一伙的吧。
http://www.programfan.com/club/post-246943.html在此为何不给我和 Matodied加分!
9 楼
wzc1996 [专家分:1680] 发布于 2007-08-18 19:48:00
[quote][quote]wzc1996你真无耻,竟然把人家的题目复制去,就把变量改一下!无耻!无耻!!超级无耻!!!哼!哼!!哼!!![/quote]
我没抄
那我就揭穿你。QB小猪、我的电脑、小精灵1号、网虫1号和你(不一定是一个人)应该都是一伙的吧。(不过QB小猪、我的电脑、小精灵1号、网虫1号)可发现是一人!
http://www.programfan.com/club/post-246943.html在此为何不给我和 Matodied加分!
[/quote]
我来回复