Pascal/Turbo Pascal - DELPHI A PASCAL

   
Vista:

DELPHI A PASCAL

Publicado por elias (46 intervenciones) el 28/04/2013 00:54:43
Deseo usar este codigo Delphi para programa en pascal pero no se por donde empezar..ayuda...:

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
const
MaxTeams = 500;
MaxRounds = MaxTeams;
MaxGames  = (MaxTeams+1) Div 2;
Home = 1;
Away = 2;
Bye : Integer = -1;
type
TGameAry = Array[1..MaxTeams] of Integer;
TRoundRobinAry = Array[1..MaxRounds,1..MaxGames,Home..Away] of Integer;
 
....
 
procedure TForm1.CreateRoundRobin(var RoundRobinAry: TRoundRobinAry;
  const Teams: Integer);
var
GameAry : TGameAry;
Half,
Rounds,
Bottom,
SwitchBottom,
TempGameValue,
i,
ii,
iii : Integer;
begin
For i := 1 to MaxRounds do
For ii := 1 to MaxGames do
  For iii := 1 to 2 do
    RoundRobinAry[i][ii][iii] := 0;
IF ((Teams  MaxTeams)) Then exit;
//Initilize Team Array with Team Numbers
For i := 1 to Teams do
GameAry[i] := i;
if (Teams then For i := (Teams+1) to MaxTeams do
      GameAry[i] := 0;
Half := (Teams-1) Div 2;
IF ((Teams Mod 2)=0)
Then Begin
     Rounds := Teams - 1;
     Bottom := Teams - 2;
     SwitchBottom := Bottom + 1;
   End
else Begin
     Rounds := Teams;
     Bottom := Teams - 1;
     SwitchBottom := Teams;
end;
for i := 1 to Rounds do
begin
for ii := 1 to Half do
  begin
   RoundRobinAry[i][ii][Home] := GameAry[ii];
   RoundRobinAry[i][ii][Away] := GameAry[Bottom-ii+1];
  end;
If ((Teams - Bottom) = 2)  // if even number of teams
  then begin
     if i mod 2 = 0
     then begin
       RoundRobinAry[i][Half+1][Home] := GameAry[SwitchBottom];
       RoundRobinAry[i][Half+1][Away] := GameAry[Bottom+2];
     end
     else begin
       RoundRobinAry[i][Half+1][Away] := GameAry[SwitchBottom];
       RoundRobinAry[i][Half+1][Home] := GameAry[Bottom+2];
     end
  end
  else begin // if odd number of teams then idle team gets a bye
     RoundRobinAry[i][Half+1][Home] := GameAry[SwitchBottom];
     RoundRobinAry[i][Half+1][Away] := Bye;
  end;
//rotate value of gameary
TempGameValue := GameAry[SwitchBottom];
for ii := SwitchBottom downto 2 do
  GameAry[ii] := GameAry[ii-1];
GameAry[1] := TempGameValue;
end;
end;


You can easily print the result to a richedit with a push of a button.

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
procedure TForm1.Button1Click(Sender: TObject);
const NoOfTeams : integer = 7;
var roundrobinary : TRoundRobinAry;
 
begin
RichEdit1.Clear;
CreateRoundRobin(RoundRobinAry,NoOfTeams);
PrintFullChart(RoundRobinAry);  //see below
end;
 
 
Procedure Tform1.PrintFullChart(const RoundRobinAry: TRoundRobinAry;);
var i,ii : integer;
begin
  richedit1.Lines.BeginUpdate;
  i := 1;
  ii := 1;
  repeat;
    Richedit1.Lines.Add(Format('Round : %d', [i]));
    while (RoundRobinAry[i][ii][Home]  0) do
    begin
    if RoundRobinAry[i][ii][away]  - 1 then
          Richedit1.Lines.Add(Format('Home : %3.0d  Away: %3.0d', [RoundRobinAry[i][ii][Home],RoundRobinAry[i][ii][Away]]))
      else
          Richedit1.Lines.Add(Format('BYE FOR TEAM : %3.0d', [RoundRobinAry[i][ii][Home]]));
      inc(ii);
    end;
    inc(i);
    ii := 1;
  until (RoundRobinAry[i][ii][Home] = 0);
  Richedit1.Lines.endupdate;
end;
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

DELPHI A PASCAL

Publicado por ramon (2072 intervenciones) el 28/05/2013 19:54:16
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
{A qui tienes una parte la otra es mas complicada de acoplar espero te sirva}
 
uses
   crt;
const
MaxTeams = 11;
MaxRounds = MaxTeams;
MaxGames  = (MaxTeams+1) Div 2;
Home = 1;
Away = 2;
Bye : Integer = -1;
 
type
TGameAry = Array[1..MaxTeams] of Integer;
TRoundRobinAry = Array[1..MaxRounds,1..MaxGames,Home..Away] of Integer;
 
var
  robin : TRoundRobinAry;
  i, e, t : integer;
 
  procedure CreateRoundRobin(var RoundRobinAry: TRoundRobinAry;
                                              const Teams: Integer);
  var
     GameAry : TGameAry;
     Half, Rounds, Bottom, SwitchBottom, TempGameValue,
     i, ii, iii : Integer;
     begin
        For i := 1 to MaxRounds do
         For ii := 1 to MaxGames do
          For iii := 1 to 2 do
          RoundRobinAry[i][ii][iii] := 0;
          IF ((Teams  > MaxTeams)) Then
          exit;
           For i := 1 to Teams do
            GameAry[i] := i;
         if (Teams < MaxTeams) then
         For i := (Teams + 1) to MaxTeams do
         GameAry[i] := 0;
         Half := (Teams - 1) Div 2;
         IF ((Teams Mod 2) = 0) Then
         Begin
           Rounds := Teams - 1;
           Bottom := Teams - 2;
           SwitchBottom := Bottom + 1;
        End
     else
      Begin
         Rounds := Teams;
         Bottom := Teams - 1;
         SwitchBottom := Teams;
     end;
        for i := 1 to Rounds do
        begin
          for ii := 1 to Half do
          begin
            RoundRobinAry[i][ii][Home] := GameAry[ii];
            RoundRobinAry[i][ii][Away] := GameAry[Bottom - ii + 1];
          end;
         If ((Teams - Bottom) = 2) then
         begin
           if i mod 2 = 0 then
           begin
           RoundRobinAry[i][Half+1][Home] := GameAry[SwitchBottom];
           RoundRobinAry[i][Half+1][Away] := GameAry[Bottom + 2];
          end
     else
       begin
       RoundRobinAry[i][Half+1][Away] := GameAry[SwitchBottom];
       RoundRobinAry[i][Half+1][Home] := GameAry[Bottom + 2];
     end
  end
  else
    begin
     RoundRobinAry[i][Half+1][Home] := GameAry[SwitchBottom];
     RoundRobinAry[i][Half+1][Away] := Bye;
   end;
     TempGameValue := GameAry[SwitchBottom];
      for ii := SwitchBottom downto 2 do
      GameAry[ii] := GameAry[ii-1];
      GameAry[1] := TempGameValue;
    end;
  end;
 
 
begin
    CreateRoundRobin(robin,MaxTeams);
    clrscr;
    for t := 1 to MaxTeams - 1 do
    begin
     write('Jornada [',t,'] ');
     for i := 1 to MaxTeams div 2 do
     begin
      if robin[t,i,e] <> 0 then
      write(robin[t,i,1],' = ',robin[t,i,2],' | ');
     end;
     if robin[t,i,e] <> 0 then
      writeln;
    end;
      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