您好,登錄后才能下訂單哦!
DECLARE
TYPE seq_st_tt IS TABLE OF INT;
seq_st seq_st_tt := seq_st_tt(20,-10,-5,-3,5,4,-2,7,40);
tmpsum INT := 0;
maxval INT :=seq_st(1);
spos INT := 1;
epos INT := 1;
nspos INT := 1;
nepos INT := 1;
BEGIN
FOR i IN 1..seq_st.count LOOP
tmpsum := tmpsum + seq_st(i);
IF(tmpsum < 0) THEN
nspos := i + 1;
nepos := i + 1;
tmpsum := 0;
ELSIF(tmpsum >= maxval) THEN
spos := nspos;
epos := nepos;
nepos := nepos + 1;
maxval := tmpsum;
ELSE
nepos := nepos + 1;
END IF;
END LOOP;
dbms_output.put_line('the max linear sequence from '||spos||' to '||epos||' is '||maxval);
END;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。