Re: [问题] 一维矩阵资料 各元素比大小

楼主: jubilee2 (3321)   2016-09-18 03:59:31
你的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
作者: e84011095 (天龙鲁蛇)   2016-09-25 18:57:00
谢谢

Links booklink

Contact Us: admin [ a t ] ucptt.com