Desafio !!!

Started by anakim, 21 de August , 2006, 09:02:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

anakim

Olá a todos gostei do desafio em C/C++ e fiz um no delphi abaixo objetivo:

Objetivo: Criar Formatador de Texto

Explicacao: Scanei o texto e substitua o espaco por _ o a por 4 ... abaixo lista d substituicao:

A = 4 , S = Z,  R = 8... e assim por diante faca a substituicao de acordo com sua personalidade OBS: objetivo substituir strings sem usar componentes prontos, flws ae!!!
Why use Windows? If I have the door ;-)

OnlyOne

s : String;
i : Integer;

for i := 0 to Length(s) do
 begin

 if s = 'A' then
  begin
  s = '4';
  end;

  if s = 'S' then
  begin
  s = 'Z';
  end;

  if s = 'R' then
  begin
  s = '8';
  end;

  if s = ' ' then
  begin
  s = '_';
  end;


 end; //for
No céu toca Joy Division


OnlyOne

perdoem o post duplo mas e q deveria aparecer assim :

if s[ i ] = 'A' then
 begin
 s[ i ] = '4';
 end;
No céu toca Joy Division


TGA

TGA

Amigo, desculpe, mais vc testou realmente se isso funciona?

pode se criar uma simples função para tal simples desafio desafio, deixo aqui como exemplo o codigo de uma unit.pas
que a fiz para mostrar de exemplo, bastando chamar a função criardo para fazer esse tipo de encryptação;

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

{-----------------------------------------
 Substitui um caractere dentro da string
 -----------------------------------------}

function BuscaTroca(Text,Busca,Troca : string) : string;
var n : integer;

begin
for n := 1 to length(Text) do
  begin
  if Copy(Text,n,1) = Busca then
  begin
  Delete(Text,n,1);
  Insert(Troca,Text,n);
  end;
  end;
Result := Text;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
 Label1.Caption := 'TGA - UMA STRING QUALQUER';

  { A = 4 }
 Label1.Caption:= BuscaTroca( Label1.Caption ,'A','4');

  { S = Z }
 Label1.Caption:= BuscaTroca( Label1.Caption ,'S','Z');

   {  R = 8 }
 Label1.Caption:= BuscaTroca( Label1.Caption ,'R','8');

end;



end.

Abraços..
"A IMAGINAÇÃO É MAIS IMPORTANTE QUE O CONHECIMENTO"
__________________________________________________________

anakim

ae esse desafio é simples porém tem algo amais q é a simplicidade no qual vai ser criada a funcao, e gostei dos exemplos qt menos melhor, aguardo mais exemplos diferentes.
Why use Windows? If I have the door ;-)