Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
40
Task/Best-shuffle/Pascal/best-shuffle.pas
Normal file
40
Task/Best-shuffle/Pascal/best-shuffle.pas
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
program BestShuffleDemo(output);
|
||||
|
||||
function BestShuffle(s: string): string;
|
||||
|
||||
var
|
||||
tmp: char;
|
||||
i, j: integer;
|
||||
t: string;
|
||||
begin
|
||||
t := s;
|
||||
for i := 1 to length(t) do
|
||||
for j := 1 to length(t) do
|
||||
if (i <> j) and (s[i] <> t[j]) and (s[j] <> t[i]) then
|
||||
begin
|
||||
tmp := t[i];
|
||||
t[i] := t[j];
|
||||
t[j] := tmp;
|
||||
end;
|
||||
BestShuffle := t;
|
||||
end;
|
||||
|
||||
const
|
||||
original: array[1..6] of string =
|
||||
('abracadabra', 'seesaw', 'elk', 'grrrrrr', 'up', 'a');
|
||||
|
||||
var
|
||||
shuffle: string;
|
||||
i, j, score: integer;
|
||||
|
||||
begin
|
||||
for i := low(original) to high(original) do
|
||||
begin
|
||||
shuffle := BestShuffle(original[i]);
|
||||
score := 0;
|
||||
for j := 1 to length(shuffle) do
|
||||
if original[i][j] = shuffle[j] then
|
||||
inc(score);
|
||||
writeln(original[i], ', ', shuffle, ', (', score, ')');
|
||||
end;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue