Показать сообщение отдельно
  #3  
Старый 27.04.2010, 08:02
Аватар для Bars1992
Bars1992 Bars1992 вне форума
Активный
 
Регистрация: 24.04.2010
Адрес: Украина, Кременчуг
Сообщения: 249
Репутация: 22
По умолчанию

Класная задачка мне понравилось пришлось попаритца но все же решил
Вот код:
Код:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    sButton1: TsButton;
    procedure sButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
var
a,b:set of char;

procedure dod(list:TstringList;s:string);
 begin
  if list.IndexOfname(s)=-1 then list.Add(s+'=1')
                            else list.Values[s]:=inttostr(strtoint(list.Values[s])+1);

 end;

procedure TForm1.sButton1Click(Sender: TObject);
var
 sOpenDialog1: TOpenDialog;
 income,list:TstringList;
 i,j,x1,x2:integer;
 k:string;

begin
 sOpenDialog1 := TOpenDialog.Create(nil);
 sOpenDialog1.Filter := 'òåñêòîâûé ôàéë|*.txt';
 income:=TstringList.Create;
 list:=TstringList.Create;
 a:=['0'..'9','A'..'Z','a'..'z','À'..'ï','ð'..'ÿ'];
 b:=['!'..'/',':'..'@','\'..#39];
 if not sopenDialog1.Execute then exit;
 income.LoadFromFile(SopenDialog1.FileName);
 for i:=0 to income.Count-1 do
  begin
  k:='';
  for j:=2 to length(income[i]) do
   begin
     x1:=2;
     x2:=2;
     if income[i][j-1]=' ' then x1:=0;
     if income[i][j-1]in A then x1:=1;
     if income[i][j-1]in B then x1:=2;
     if income[i][j]=' ' then x2:=0;
     if income[i][j]in A then x2:=1;
     if income[i][j]in B then x2:=2;
     if x1<>x2 then
      begin
      if j=length(income[i]) then
        begin
         k:=k+income[i][j-1];
         dod(list,k);
         dod(list,income[i][j]);
         break;
        end;
       k:=k+income[i][j-1];
       dod(list,k);
       k:='';
      end
       else
      k:=k+income[i][j-1];
   end;
   end;
 list.Sort;
 list.SaveToFile(SopenDialog1.FileName);
 income.Free;
 list.Free;
 sOpenDialog1.Free;
 close;

end;

end.
Результат сохраняется в тот же файл
__________________
Не твори зла, и жизнь повернется к тебе передом
Ответить с цитированием