unit utransponer;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


{ saca la primer palabra del string s}
function NextPal(var s: string ):string;
var
	i: integer;
	ts: string;
begin
  s:= trim( s );
  i:= pos( #9, s );
  if i > 0 then
  begin
    ts:=  copy(s, 1, i-1);
    delete(s, 1, i);
  end
  else
  begin
    ts:= s;
    s:= '';
  end;
	result:= ts;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  f, sal: textfile;
  r, s: string;
  cnt: integer;
begin
  assignfile( f, 'simres_31x1.xlt' );
  reset( f );
  assignfile( sal, 'sal.xlt' );
  rewrite( sal );
  while not eof( f ) do
  begin
    readln( f, r );
    cnt:= 0;
    s:= nextpal( r );
    while s <> '' do
    begin
      inc(cnt );
      write( sal , #9, s );
      s:= nextpal( r );
      if cnt = 1 then
      begin
        writeln( sal );
        cnt:= 0;
      end;
    end;
    writeln( sal );
  end;


  closefile( sal );
  closefile( f );

end;

end.
