Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- contains
- subroutine sort_indexes(A, indexes)
- integer, intent(inout) :: A(:), indexes(:)
- integer :: i, loc, N, sub
- N = size(A)
- do i = 1, N
- !Сортировка значений в первой строке массива по возрастанию
- loc = MaxLoc(A(1:N-i+1), dim = 1)
- sub = A(N-i+1)
- A(N-i+1) = A(loc)
- A(loc) = sub
- !Сортировка индексов строк массива по возрастанию элементов первой строки
- sub = indexes(N-i+1)
- indexes(N-i+1) = indexes(loc)
- indexes(loc) = sub
- end do
- end subroutine
- end module
- PROGRAM EX7_29
- use environment
- use functions
- implicit none
- character(*), parameter :: input = "../data/input", output = "../data/output"
- integer(R_) :: in = 1, out = 2
- integer(R_), allocatable :: A(:,:), indexes(:)
- integer(R_) :: N, i, j
- character(:), allocatable :: fmt
- open(newunit = in, file = input)
- read(in,*) N
- allocate(A(N,N))
- read(in,*) (A(:,j), j = 1, N)
- close(in)
- allocate(indexes(N))
- indexes = [(i, i = 1, N)]
- write(*,*) indexes
- call sort_indexes(A(:,1), indexes)
- write(*,*)
- write(*,*) indexes
- write(*,"(4i4)") (A(:, indexes(i)), i = 1, N)
- fmt = "("//N//"i4)"
- open(newunit = out, file = output)
- write(out, fmt) (A(:, indexes(i)), i = 1, N)
- close(out)
- end program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement