Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program permutations;
- function isConsonant(ch: Char): Boolean;
- begin
- ch := UpCase(ch);
- isConsonant := not (ch in ['A', 'E', 'I', 'O', 'U']);
- end;
- function isValidChain(chain: string): Boolean;
- begin
- isValidChain := isConsonant(chain[1]) and
- (chain[2] in ['C', 'D', 'F']) and
- ((UpCase(chain[3]) in ['A', 'E', 'I', 'O', 'U']) or (isConsonant(chain[3]) and (chain[3] <> chain[2]))) ;
- end;
- procedure generatePermutations(prefix, remaining: string; var counter: Integer);
- var
- i: Integer;
- begin
- if length(prefix) = 3 then
- begin
- if isValidChain(prefix) then
- counter := counter + 1;
- Exit;
- end;
- for i := 1 to length(remaining) do
- generatePermutations(prefix + remaining[i], Copy(remaining, 1, i - 1) + Copy(remaining, i + 1, length(remaining)), counter);
- end;
- var
- counter: Integer;
- str: string;
- begin
- str := 'ABCDEF';
- counter := 0;
- generatePermutations('', str, counter);
- WriteLn('Количество подходящих цепочек: ', counter);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement