这里是一种非链表方法
[Fortran] 纯文本查看 复制代码 Program main
Implicit None
Integer , parameter :: N = 41 , K = 3
logical :: isDie(N)
integer :: nAlive , nCurr , i
isDie = .false.
nCurr = 1
nAlive= N
Do
if( nAlive < K ) exit
Do i = 1 , K
nCurr = next()
End Do
isDie(nCurr) = .true.
nAlive = nAlive - 1
End Do
Do i = 1 , N
if( .not.isDie(i) ) write(*,*) i
End Do
contains
integer function next()
integer :: nt
nt = nCurr + 1
do
if( nt > N ) nt = 1
if( .not.isDie(nt) ) then
next = nt
return
end if
nt = nt + 1
end do
end function next
End Program main |