SAS中文论坛
标题:
求逆序总数
[打印本页]
作者:
shiyiming
时间:
2010-5-9 14:00
标题:
求逆序总数
例如有序列:7 ,5,8,9.
对于7,有两个数8和9大于它.5有两个数8和9大于它.8有一个数9大于它;那么逆序总数就为5.怎样编程实现呢?
希望得到大家的帮助,谢谢
作者:
shiyiming
时间:
2010-5-9 14:43
标题:
Re: 求逆序总数
[code:3e4e0w4n]data temp(drop=i j);
input x1-x4;
array arr{*} x1-x4;
sum=0;
do i=1 to dim(arr);
do j=i to dim(arr);
if arr(j) gt arr(i) then sum+1;
end;
end;
datalines;
7 5 8 9
1 3 3 4
4 6 3 1
6 9 4 1
;[/code:3e4e0w4n]
作者:
shiyiming
时间:
2010-5-9 15:36
标题:
Re: 求逆序总数
可以不用数组做么?
作者:
shiyiming
时间:
2010-5-9 15:45
标题:
Re: 求逆序总数
比如,数据是这样的:
data temp;
input x@@;
cards;
7 5 8 9
1 3 3 4
4 6 3 1
6 9 4 1
;
怎么求逆序总数呢
作者:
shiyiming
时间:
2010-5-9 16:25
标题:
Re: 求逆序总数
[code:2v1rrqco]data temp;
input x @@;
id=_n_;
cards;
7 5 8 9
1 3 3 4
4 6 3 1
6 9 4 1
;
proc sql noprint;
select count(a.x) into :count
from temp a inner join temp b on b.id>a.id and b.x>a.x;
quit;
%put NOTE:*** COUNT=%trim(&count) ***;[/code:2v1rrqco]
作者:
shiyiming
时间:
2010-5-9 16:45
标题:
Re: 求逆序总数
谢谢hopewell
欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/)
Powered by Discuz! X3.2