主题:HELP!加分
小精灵LS
[专家分:580] 发布于 2007-08-14 09:51:00
旅馆有100个房间,从1到100编号。第一个服务员来,把所有房门都打开;第二个服务员来,把所有编号是2的倍数的房门作相反的处理(即将原来关着的房门打开,打开着的房门关上);第三个服务员来,把所有编号是3的倍数的房门作相反处理;以后第4至第100个服务员都把所有编号是第几(4--100)的倍数的房门作相反处理。编程求出第100个服务员走后,有哪些门是开着的。
回复列表 (共10个回复)
沙发
小精灵1号 [专家分:1040] 发布于 2007-08-14 09:54:00
CLS
DIM A(100)
FOR I = 1 TO 100
FOR J = I TO 100 STEP I
A(J) = 1 - A(J)
NEXT J, I
FOR I = 1 TO 100
IF A(I) = 1 THEN PRINT I; : S = S + 1
NEXT I
PRINT : PRINT "s="; S
END
板凳
游戏之王 [专家分:540] 发布于 2007-08-14 09:56:00
CLS
DIM A(100)
FOR I = 1 TO 100:FOR J = I TO 100 STEP I:A(J) = 1 - A(J):NEXT J, I
FOR I = 1 TO 100
IF A(I) = 1 THEN PRINT I; : S = S + 1
NEXT I:PRINT : PRINT "s="; S:END
3 楼
网虫一号 [专家分:1230] 发布于 2007-08-14 09:58:00
2 楼
CLS
DIM A(100)
FOR I = 1 TO 100:FOR J = I TO 100 STEP I:A(J) = 1 - A(J):NEXT J, I
FOR I = 1 TO 100
IF A(I) = 1 THEN PRINT I; : S = S + 1
NEXT I:PRINT : PRINT "s="; S
END
4 楼
我的电脑 [专家分:990] 发布于 2007-08-14 10:35:00
CLS
DIM A(100)
FOR I = 1 TO 100:FOR J = I TO 100 STEP I:A(J) = 1 - A(J):NEXT J, I
FOR I = 1 TO 100
IF A(I) = 1 THEN PRINT I; : S = S + 1
NEXT I:PRINT : PRINT "s="; S:END
5 楼
QB小猪 [专家分:1200] 发布于 2007-08-14 10:36:00
CLS
DIM A(100)
FOR I = 1 TO 100
FOR J = I TO 100 STEP I
A(J) = 1 - A(J)
NEXT J, I
FOR I = 1 TO 100
IF A(I) = 1 THEN PRINT I; : S = S + 1
NEXT I
PRINT : PRINT "s="; S
END
6 楼
wzc1996 [专家分:1680] 发布于 2007-08-14 12:21:00
CLS
DIM a(100)
FOR i = 1 TO 100: a(i) = 1: NEXT
FOR i = 2 TO 100
FOR j = 1 TO 100
IF j / i = INT(j / i) THEN a(j) = -a(j)
NEXT
NEXT
FOR i = 1 TO 100: IF a(i) = 1 THEN
PRINT i;
NEXT
END
7 楼
小小傻瓜 [专家分:150] 发布于 2007-08-14 14:59:00
6楼的,NEXT 都没有!
CLS
DIM A(100)
FOR I = 1 TO 100
FOR J = I TO 100 STEP I
A(J) = 1 - A(J)
NEXT J, I
FOR I = 1 TO 100
IF A(I) = 1 THEN PRINT I; : S = S + 1
NEXT I
PRINT : PRINT "s="; S
END
8 楼
wzc1996 [专家分:1680] 发布于 2007-08-14 19:00:00
你的还是抄的呢!
9 楼
QB爱好者 [专家分:370] 发布于 2007-08-14 19:57:00
[size=2]CLS
DIM A(100)
FOR I=1 TO 100
FOR J=1 TO 100\I
A(J*I)=(A(J*I)+1) MOD 2
NEXT J,I
FOR I=1 TO 100
IF A(I)=1 THEN ? I;
NEXT I
END[/size]
10 楼
QB爱好者 [专家分:370] 发布于 2007-08-28 12:53:00
加分!!!!
我来回复