0 Members and 1 Guest are viewing this topic.
blabla | times: 1blablabla | times: 3bladsala | times: 1bladfd | times: 12blafdsala | times: 14blaasla | times: 5
procedure sort();begin temp := ixsplit(ReadFile('w.txt'), chr(13)+chr(10)); for i:=0 to ArrayHigh(temp) do begin cutlength := length(temp[i]) - (length(GetPiece(temp[i],' | times: ',1))); _count[i] := strtoint(Copy(temp[i],cutlength,length(temp[i]))) + 1; temp[i] := Copy(temp[i],1,cutlength) + inttostr(_count[i]); end if (_count[i] < _count[i+1]) and ((i+1) < ArrayHigh(temp)) then begin _tempcount := temp[i]; temp[i] := temp[i+1]; temp[i+1] := temp[i]; writestring:=writestring+temp[i]+#13+#10; end WriteFile('w.txt',writestring); writestring:='';end;
WriteLnFile('scorez.txt',IntToStr(IDToName(i)) + #3 + IntToStr(Tries[i]))
var i, j, best: byte; // change to word if you want to sort more than 255 scores checked: array[1..<ammount of elements to sort>] of boolean; nomore: boolean; tries: array[1..<ammount of elements to sort>] of word;begin for i:= 1 to <ammount of elements to sort> do tries[i]:= <assign score value>; j:= 1; for i:= 1 to <ammount of elements to sort> do checked[i]:= false; repeat best:= 0; for i:= 1 to <ammount of elements to sort> do if not checked[i] then if (best = 0) or (tries[i] < tries[best]) then best:= i; checked[best]:= true; // HERE YOU CAN DO STUFF WITH THE SORTED TRIES, "best" is current score ID(if you read them line-by-line it will be the line number), "j" is position on the 'list' j:= j + 1; nomore:= true; for i:= 1 to <ammount of elements to sort> do if not checked[i] then nomore:= false; until nomore;end;
function ZeroFill(S: string; Peak: integer; IsEnabled: boolean): string;var i, m: integer;begin if (IsEnabled) then begin m:= Peak - length(S); for i:= 1 to m do begin S:= '0' + S; end; end; result:= S;end;procedure QuickSort(var AOS: array of string; Left, Right: integer; Ival: boolean; SortBy: integer);var b, e, Pivot: string; i, l, m, r: integer;begin if (Right > Left) then begin for i:= 0 to Right do begin e:= GetPiece(AOS[i], '|', SortBY); if (length(e) > m) then begin m:= length(e); end; end; l:= Left; r:= Right; Pivot:= ZeroFill(GetPiece(AOS[Random(Left, Right)], '|', SortBy), m, Ival); repeat while ((ZeroFill(GetPiece(AOS[l], '|', SortBy), m, IVal) > Pivot) and (l < Right)) do begin Inc(l, 1); end; while ((ZeroFill(GetPiece(AOS[r], '|', SortBy), m, IVal) < Pivot) and (r > Left)) do begin Dec(r, 1); end; if (l <= r) then begin b:= AOS[r]; AOS[r]:= AOS[l]; AOS[l]:= b; Inc(l, 1); Dec(r, 1); end; until (l >= r); if (Left < r) then begin QuickSort(AOS, Left, r, Ival, SortBy); end; if (Right > l) then begin QuickSort(AOS, l, Right, Ival, SortBy); end; end else begin exit; end;end;
QuickSort(temp, 0, ArrayHigh(temp), true, 2); for i:=0 to ArrayHigh(temp) do begin writestring:=writestring+temp[i]+#13+#10; end WriteFile('whois_data/'+iprange+'.txt',writestring); writestring:='';
GetPiece(AOS[l], '| times: ', SortBy)
I tried QuickSort by CurryWurst - it change lines order, but not in the right way.Code: [Select] QuickSort(temp, 0, ArrayHigh(temp), true, 2); for i:=0 to ArrayHigh(temp) do begin writestring:=writestring+temp[i]+#13+#10; end WriteFile('whois_data/'+iprange+'.txt',writestring); writestring:='';in QuickSort in GetPiece I use "| times: " as a separator.Code: [Select]GetPiece(AOS[l], '| times: ', SortBy)(same for aos[r] and aos[random])What's wrong?
The problem is you only delimit "blabbla" from "times: 14" which would require an additional split.Why don't delimit all your segments by '|': "blabla|times|14" ?
Try this: QuickSort(temp, 0, ArrayHigh(temp), true, 1);
Quote from: CurryWurst on October 23, 2009, 06:36:46 amTry this: QuickSort(temp, 0, ArrayHigh(temp), true, 1);Works, thanks.
Quote from: CurryWurst on October 23, 2009, 06:36:46 amThe problem is you only delimit "blabbla" from "times: 14" which would require an additional split.Why don't delimit all your segments by '|': "blabla|times|14" ?My only values are "blabla" and "14", "| times" is my delimit. I don't use "#9" or "|" because nicks can contain it. (theres a clan with tag "#two_random_numbers")
procedure ZeroFill(var S: string; const Count: word);var i: word; b: string;begin for i:= 1 to Count do begin b:= b + '0'; end; S:= b + S;end;function SelectionSort(var AOS: array of string; const SortBy: word; const Ival: boolean; const Delim: string): integer;var i, j, m, Index: integer; C1, C2: string; b: string;begin Index:= GetArrayLength(AOS) - 1; for i:= 0 to Index do begin if (length(GetPiece(AOS[i], Delim, SortBy)) > m) then begin m:= length(GetPiece(AOS[i], Delim, SortBy)); end; end; i:= 1; while (j < Index) do begin C1:= GetPiece(AOS[j], Delim, SortBy); C2:= GetPiece(AOS[j + i], Delim, SortBy); if (Ival) then begin ZeroFill(C1, m - length(C1)); ZeroFill(C2, m - length(C2)); end; if (C1 < C2) then begin b:= AOS[j]; AOS[j]:= AOS[j + i]; AOS[j + i]:= b; Inc(Result, 1); end; if (j + i < Index) then begin Inc(i, 1); end else begin i:= 1; Inc(j, 1); end; end;end;