五号签命中问题研究.rar
(1.27 KB)
程序代码:
*!* http://bbs.bccn.net/thread-505144-1-1.html *!* 论坛上狐友“厨师王德榜”发的题目 *!* 也来发一个算法问题,其实是小学生的课后思考题. *!* 我自己做起来很懵逼...... *!* 题目如下: *!* 有九个同学,姑且给他们背后贴上纸条,纸条上编号分别为:A,B,C...I *!* 让他们站成一个圆圈,由A同学开始,从1开始报数, *!* 当有同学报"5"时,这个同学退出圈子. *!* 这个同学之后的一个同学,重新开始从1开始报数, *!* 当有同学报"5"时,这个同学退出圈子.周而复始... *!* ...... *!* 直到剩下最后一个同学. *!* 问:这个同学,背后纸条上编号为? *!* 头脑里过一遍,或者纸面上写写画画,或许能找到答案, *!* 但是我要的不是答案,而是过程,而且把这个过程,用程序语言描述出来. *!* 程序运行后,希望输出这样的效果: *!* 第1轮,E同学退出... *!* 第2轮,A同学退出... *!* ... *!* 第?轮,?同学退出...至此,只剩下最后一位?同学. *!* 欢迎各位用你们擅长的编程语言来求得答案,并展示过程. *!* 时间:2021-3-17 CLEAR CLEAR ALL SET SAFETY OFF PUBLIC kz,nRecc,nYs CLOSE DATABASES SELECT * from ys INTO TABLE jgcl SELECT * from ys WHERE 1=2 INTO TABLE qhpx kz=.T. DO WHILE kz=.T. SELECT jgcl GO top nRecc=RECCOUNT() DO CASE CASE nRecc>=5 GO 5 COPY TO ls NEXT 1 COPY TO ls1 FOR RECNO()>5 COPY TO ls2 FOR RECNO()<5 SELECT qhpx APPEND FROM ls SELECT jgcl ZAP APPEND FROM ls1 APPEND FROM ls2 CASE nRecc<5 IF nRecc=1 kz=.F. ELSE nYs=MOD(5,nRecc) IF nRecc>nYs GO nYs COPY TO ls NEXT 1 COPY TO ls1 FOR RECNO()>nYs COPY TO ls2 FOR RECNO()<nYs SELECT qhpx APPEND FROM ls SELECT jgcl ZAP APPEND FROM ls1 APPEND FROM ls2 ELSE nYs=MOD(nYs,nRecc) GO nYs COPY TO ls NEXT 1 COPY TO ls1 FOR RECNO()>nYs COPY TO ls2 FOR RECNO()<nYs SELECT qhpx APPEND FROM ls SELECT jgcl ZAP APPEND FROM ls1 APPEND FROM ls2 ENDIF ENDIF ENDCASE ENDDO SELECT qhpx GO top SCAN ? "第"+ALLTRIM(STR(RECNO()))+"位出局的同学是: " + yxrdm ENDSCAN SELECT jgcl ? "最后剩下的同学是: "+yxrdm CLOSE DATABASES RETURN
只求每天有一丁点儿的进步就可以了