掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
配列の順位付け (ID:150886)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
chatgptの登場でDelphi7でソートプログラムをお願いしました。できあがったコードでソートしてみたのですが、やはりバージョンが古いのか思った結果が得られません。 function get3(const ind, ten: array of integer; var jun: array of integer): integer; var i, j, k, n: integer; aind, aten, ajun: array of integer; begin n := Length(ind); SetLength(aind, n); SetLength(aten, n); SetLength(ajun, n); for i := 0 to n - 1 do begin aind[i] := ind[i]; aten[i] := ten[i]; ajun[i] := jun[i]; // jun を ajun にコピー end; for i := 0 to n - 2 do for j := i + 1 to n - 1 do if aten[i] < aten[j] then begin k := aten[i]; aten[i] := aten[j]; aten[j] := k; k := aind[i]; aind[i] := aind[j]; aind[j] := k; k := ajun[i]; ajun[i] := ajun[j]; ajun[j] := k; end else if aten[i] = aten[j] then begin if ajun[i] > ajun[j] then begin k := ajun[i]; ajun[i] := ajun[j]; ajun[j] := k; end; end; Result := 0; for i := 1 to n do begin if aind[i - 1] = 0 then Continue; if (i > 1) and (aten[i - 1] = aten[i - 2]) then begin for k := i-2 downto 0 do begin if (aten[k] > aten[i-1]) or ((aten[k] = aten[i-1]) and (ajun[k] < ajun[i-1])) then begin jun[aind[i - 1]] := jun[aind[k]]; Break; end; end; end else jun[aind[i - 1]] := i; end; // 最大順位を返す Result := jun[1]; for i := 2 to n do if jun[i] > Result then Result := jun[i]; end; データ表示を確認すると ind:=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] Ten := [33, 40, 23, 35, 35, 50, 32, 32, 0, 31, 24, 38, 30, 35, 42, 37]; jun:= [1, 2, 1, 4, 2, 3, 1, 6, 7, 1, 9, 11, 4, 12, 6, 3]; やはりjun[i]だけ数値が違います。jun=[7,10,1,9,11,2,13,6,8,3,12,4,15,14,5,16]この結果が欲しいんですよね。やっぱりバージョンアップしか道は無いのか?
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.