作者jubilee2 (3321)
看板Fortran
标题Re: [问题] 一维矩阵资料 各元素比大小
时间Sun Sep 18 03:59:31 2016
你的A应该是指整理过後的Y吧
我从头(X,Y)开始写一个解答
基本上排序有点偷懒,就简单判断X(i)>X(j)就代表所有排序在j之後的元素
其他有问题再提出来吧。
function get_P(X,Y) result(P)
implicit none
! input
real, intent(in), allocatable :: X(:), Y(:)
integer :: i, j
! output
integer :: P
P=0
do i=1,size(X)
do j=1,size(X)
if(X(i) > X(j) .and. i /= j) then
if(Y(i)>Y(j))then
P=P+1
end if
end if
end do
end do
end function get_P
function get_M(X,Y) result(M)
! input
real, intent(in), allocatable :: X(:), Y(:)
integer :: i
! output
integer :: M
M=0
do i=1,size(X)
do j=1,size(X)
if(X(i) > X(j) .and. i /= j) then
if(Y(i)<Y(j))then
M=M+1
end if
end if
end do
end do
end function get_M
program project01
implicit none
real,allocatable :: X(:),Y(:)
integer :: maxsize, i
interface
function get_P(X,Y)
real, dimension(:) :: X,Y
integer :: get_P
end function get_P
function get_M(X,Y)
real, dimension(:) :: X,Y
integer :: get_M
end function get_M
end interface
integer :: P,M,S
maxsize=110
allocate( X(maxsize),Y(maxsize) )
X=0.0d0
Y=0.0d0
!open(10,file='mtempnorth.txt')
do i=1,maxsize
!read(10,*) A(i)
! get example
X(i)=rand()
Y(i)=rand()
end do
!close(10)
P=get_P(X,Y)
M=get_M(X,Y)
print*, P-M
stop
end
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 98.240.89.168
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Fortran/M.1474142374.A.BCE.html
1F:推 e84011095: 谢谢 09/25 18:57