This commit is contained in:
2026-06-30 10:44:15 -03:00
parent 718295d782
commit 1905e88fa5
+98 -16
View File
@@ -12,6 +12,8 @@ var
cpf:string;
bool:boolean;
hash:thash;
op : integer ;
cont : boolean ;
@@ -22,13 +24,13 @@ var tmp:integer;
charInt:=tmp; //ord('0')=48... ord('1')=49... dai -48 vira 0...
end;
function validacaoDeInexistencialismoDeOutroCadastroDePessoasFisicaDentroDaLista( var cpf:string; final:integer; var cpfs:thash ): boolean;
function validacaoDeInexistencialismoDeOutroCadastroDePessoasFisicaDentroDaLista( var cpf:string;var cpfs:thash ): boolean;
var
i:integer;
aux:^ptcpf;
existenciaDeTalInformacaoNaLista:boolean;
begin
aux := cpfs[final];
aux := cpfs[(charint(cpf[10]) *10+ charint(cpf[11]))];
existenciaDeTalInformacaoNaLista := false;
while (aux^.prox <> nil) and (not existenciaDeTalInformacaoNaLista) do
begin
@@ -75,7 +77,7 @@ procedure inserirCPF(var cpfs:THash; var cpf:string);
if validarCPF(cpf) then
begin
doisDigitos:=( charInt(cpf[10])*10 ) + charInt(cpf[11]); //*10 pq né, vira dezena + decimal 👍
if (not validacaoDeInexistencialismoDeOutroCadastroDePessoasFisicaDentroDaLista(cpf, doisDigitos, cpfs)) then
if (not validacaoDeInexistencialismoDeOutroCadastroDePessoasFisicaDentroDaLista(cpf, cpfs)) then
begin
new(novo);
if novo = nil then
@@ -126,7 +128,7 @@ procedure escrever(var cpfs:thash);
end;
end;
procedure buscar(final:integer);
procedure buscar(var cpfs:thash;cpf:string);
var
aux:^ptcpf;
achou:boolean;
@@ -134,31 +136,111 @@ procedure buscar(final:integer);
begin
achou:=false;
valor:= 'Nao achou';
aux := cpfs[final];
aux := cpfs[ (charint(cpf[10]) *10+ charint(cpf[11])) ];
while (aux <> nil) and (not achou) do
begin
if(aux.cpf = cpf) then
if(aux^.cpf = cpf) then
begin
achou:=true;
valor:=(aux^.cpf) ;
end;
end
else
aux:= aux^.prox;
end;
writeln(valor);
end;
procedure remover() ;
var
procedure removerCPF(var cpfs:thash;cpf:string) ;
var
aux:^ptcpf;
aux2:^ptcpf;
achou:boolean;
begin
achou:=false;
aux := cpfs[ (charint(cpf[10]) *10+ charint(cpf[11])) ];
while (aux <> nil) and (not achou) do
begin
if(aux^.cpf = cpf) then
begin
achou:=true;
aux2:=(aux^.prox) ;
end
else
aux:= aux^.prox
end;
end;
procedure cpfsInicializar ( var cpfs : thash ) ;
var
i : integer ;
begin
for i := 0 to 99 do
cpfs[i] := nil ;
end;
begin
readln(cpf);
inserirCPF(hash, cpf);
escrever(hash);
cont := false ;
op := 1 ;
cpfsInicializar(hash) ;
while not cont do
begin
writeln('ADD cpf : 1');
writeln('Validar existencia : 2');
writeln('RM cpf : 3');
writeln('exit : 0');
readln(op);
case op of
1 :
begin
writeln('Digite o cpf a ser inserido');
readln(cpf) ;
if (validarCPF(cpf)) then
begin
inserirCPF(hash, cpf);
writeln('inserido');
end
else
writeln('cpf invalido poxa');
end;
2 :
begin
writeln('Digite o cpf a ser validado a existencia');
readln(cpf) ;
if (validarCPF(cpf)) then
begin
if validacaoDeInexistencialismoDeOutroCadastroDePessoasFisicaDentroDaLista(cpf,hash) then
writeln('está na lista já')
else
writeln('num tá');
end
else
writeln('cpf invalido poxa');
end;
3:
begin
writeln('Digite o cpf a ser removido');
readln(cpf) ;
if (validarCPF(cpf)) then
begin
removerCPF(hash, cpf);
writeln('removido');
end
else
writeln('cpf invalido poxa');
end;
0 :
begin
cont:= true;
end;
else
writeln('opção invalidade ');
end;
end;
end.