Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
22
Task/Josephus-problem/Fortran/josephus-problem.f
Normal file
22
Task/Josephus-problem/Fortran/josephus-problem.f
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
program josephus
|
||||
implicit none
|
||||
integer :: n, i, k, p
|
||||
integer, allocatable :: next(:)
|
||||
read *, n, k
|
||||
allocate(next(0:n - 1))
|
||||
do i = 0, n - 2
|
||||
next(i) = i + 1
|
||||
end do
|
||||
next(n - 1) = 0
|
||||
p = 0
|
||||
do while(next(p) /= p)
|
||||
do i = 1, k - 2
|
||||
p = next(p)
|
||||
end do
|
||||
print *, "Kill", next(p)
|
||||
next(p) = next(next(p))
|
||||
p = next(p)
|
||||
end do
|
||||
print *, "Alive", p
|
||||
deallocate(next)
|
||||
end program
|
||||
Loading…
Add table
Add a link
Reference in a new issue