Pascal/Turbo Pascal - PERMUTACIONES ARREGLOS

 
Vista:

PERMUTACIONES ARREGLOS

Publicado por Gianfranco Servidio (2 intervenciones) el 15/11/2015 20:49:33
Hola, tengo un arreglo de 4 valores de tipo char.
Alguien me podria decir como hacer para hacer una funcion o algoritmo que dados 4 caracteres cualquiera entre la A y la J, me devuelva todas las posibles permutaciones entre esos 4 ? Esto tendría que tomar el caso también en que el codigo sea AAAA, no mas habria permutaciones posibles.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

PERMUTACIONES ARREGLOS

Publicado por ramon (2158 intervenciones) el 06/12/2015 13:22:35
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{Esto servirá}
 
program permutacion;
  uses
    crt;
  type
    valores = array[1..4] of char;
 
 
 
   var
     valor : valores;
     g, conta, cont : integer;
     conm : array[1..4] of char;
 
   procedure cargaletras;
   var
     letra : integer;
     s : integer;
     esta : boolean;
    begin
       cont := 1;
     repeat
        esta := false;
        letra := random(9) + 1;
        for s := cont + 1 downto 1 do
        if valor[s] = chr(letra + 65) then
        esta := true;
      if esta = false then
      begin
        valor[cont] := chr(letra + 65);
        cont := cont + 1;
        esta := false;
      end;
     until cont > 4;
     write(' El Inicio Es = ');
     for s := 1 to 4 do
     write(' ',valor[s]);
     writeln;
     writeln;
   end;
 
   procedure presenta;
   var
     dg : integer;
   begin
      for dg := 1 to 4 do
      begin
      write(' ',conm[dg]);
      end;
      writeln;
      conta := conta + 1;
   end;
 
  Procedure permutrecurs(n : Integer);
  Var
    l : Integer;
  begin
     inc(g);
     conm[n] := valor[g];
     if g = 4 then
       presenta;
      For l := 1 to 4 do
       if conm[l] = #0 then
        permutrecurs(l);
      dec(g);
      conm[n] := #0;
   end;
 
   procedure resultados;
   var
     z, i : integer;
     ch : char;
     begin
        ch := valor[1];
        i := 1;
        for z := 2 to 4 do
        begin
        if ch = valor[z] then
        begin
           i := i + 1;
        end;
       end;
       if i >= 4 then
       begin
          writeln('   No permutacion posible');
          writeln('   Pulse Una Tecla');
          readkey;
       end
     else
       begin
          permutrecurs(0);
          writeln;
          writeln('   Permutaciones Posibles = ',conta);
          writeln('   Pulse Una Tecla');
       end;
     end;
 
  begin
     clrscr;
     g := -1;
     conta := 0;
     fillchar(conm,sizeof(conm),#0);
     randomize;
     cargaletras;
     resultados;
     readkey;
  end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar