Re: [問題] 一維矩陣資料 各元素比大小

看板Fortran作者 (3321)時間7年前 (2016/09/18 03:59), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
你的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://www.ptt.cc/bbs/Fortran/M.1474142374.A.BCE.html

09/25 18:57, , 1F
謝謝
09/25 18:57, 1F
文章代碼(AID): #1NtQ2clE (Fortran)
文章代碼(AID): #1NtQ2clE (Fortran)