Update cpfs.pas
This commit is contained in:
@@ -6,7 +6,38 @@ type
|
|||||||
cpf : string;
|
cpf : string;
|
||||||
prox : TCPF;
|
prox : TCPF;
|
||||||
end;
|
end;
|
||||||
THash = array[0..99] of TCPF;
|
THash = array[0..99] of ptcpf;
|
||||||
|
|
||||||
|
var
|
||||||
|
cpf:string;
|
||||||
|
bool:boolean;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function charInt(var letra:char):integer;
|
||||||
|
var tmp:integer;
|
||||||
|
begin
|
||||||
|
tmp:=Ord(letra)- Ord('0');
|
||||||
|
charInt:=tmp; //ord('0')=48... ord('1')=49... dai -48 vira 0...
|
||||||
|
end;
|
||||||
|
|
||||||
|
function validacaoDeInexistencialismoDeOutroCadastroDePessoasFisicasDentroDaLista(var cpf:string; final:integer; cpfs:thash ): boolean;
|
||||||
|
var
|
||||||
|
i:integer;
|
||||||
|
aux:tcpf;
|
||||||
|
existenciaDeTalInformacaoNaLista:boolean;
|
||||||
|
begin
|
||||||
|
aux:= cpfs[final];
|
||||||
|
existenciaDeTalInformacaoNaLista := false;
|
||||||
|
while (aux^.prox <> nil) and (not existenciaDeTalInformacaoNaLista) do
|
||||||
|
begin
|
||||||
|
if (cpf = aux^.cpf) then
|
||||||
|
existenciaDeTalInformacaoNaLista := true
|
||||||
|
else
|
||||||
|
aux:= aux^.prox;
|
||||||
|
end;
|
||||||
|
validacaoDeInexistencialismoDeOutroCadastroDePessoasFisicasDentroDaLista:= existenciaDeTalInformacaoNaLista;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function validarCPF(var cpf:string):boolean;
|
function validarCPF(var cpf:string):boolean;
|
||||||
@@ -15,10 +46,10 @@ function validarCPF(var cpf:string):boolean;
|
|||||||
begin
|
begin
|
||||||
soma:=0;
|
soma:=0;
|
||||||
for i:=1 to 9 do
|
for i:=1 to 9 do
|
||||||
//ord('0')=48... ord('1')=49... dai -48 vira 0... *11-i, vai decrementando, *9, *8, *7...
|
// *11-i, vai decrementando, *9, *8, *7...
|
||||||
soma:=soma+(Ord(cpf[i])-48)*(11-i);
|
soma:=soma+( charInt(cpf[i]) ) * (11-i);
|
||||||
|
|
||||||
dig1 := 11 - (soma mod 11); //digito 1 pega a sobra da divisao bla bla
|
dig1 := 11 - (soma mod 11);
|
||||||
if (dig1 = 10) or (dig1 = 11) then
|
if (dig1 = 10) or (dig1 = 11) then
|
||||||
dig1 := 0;
|
dig1 := 0;
|
||||||
|
|
||||||
@@ -31,9 +62,7 @@ function validarCPF(var cpf:string):boolean;
|
|||||||
if (dig2 = 10) or (dig2 = 11) then
|
if (dig2 = 10) or (dig2 = 11) then
|
||||||
dig2 := 0;
|
dig2 := 0;
|
||||||
|
|
||||||
ValidarCPF :=
|
ValidarCPF :=dig1=charInt( cpf[10] ) and dig2=charInt( cpf[10] );
|
||||||
(dig1=(Ord(cpf[10])-48)) and (dig2=(Ord(cpf[11])-48));
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@@ -44,44 +73,40 @@ procedure inserirCPF(var cpfs:THash; var cpf:string);
|
|||||||
begin
|
begin
|
||||||
if validarCPF(cpf) then
|
if validarCPF(cpf) then
|
||||||
begin
|
begin
|
||||||
pos:=(Ord(cpf[10])-48)*10 + (Ord(cpf[11])-48); //esse ngocio pega os digitos verificadores, gpt ajudou, transformar string em int é pesadelo
|
doisDigitos:=( charInt(cpf[10])*10 ) + charInt(cpf[11]); //*10 pq né, vira dezena + decimal 👍
|
||||||
new(novo);
|
if (validacaoDeInexistencialismoDeOutroCadastroDePessoasFisicasDentroDaLista(cpf, doisDigitos, cpfs)) then
|
||||||
if novo = nil then
|
begin
|
||||||
writeln('Memoria cheia')
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
novo^.cpf := cpf;
|
|
||||||
novo^.prox := nil;
|
|
||||||
atual:= cpfs[pos];
|
|
||||||
ant:=nil;
|
|
||||||
while (atual <> nil) and (atual^.cpf < cpf) do
|
|
||||||
begin
|
|
||||||
ant := atual;
|
|
||||||
atual := atual^.prox;
|
|
||||||
end;
|
|
||||||
if ant = nil then
|
|
||||||
begin
|
|
||||||
novo^.prox := cpfs[pos];
|
|
||||||
cpfs[pos] := novo;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
novo^.prox := atual;
|
|
||||||
ant^.prox := novo;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
writeln('CPF INVALIDO');
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
new(novo);
|
||||||
|
if novo = nil then
|
||||||
|
writeln('Memoria cheia')
|
||||||
var
|
else
|
||||||
hash: THash;
|
begin
|
||||||
cpf:string;
|
novo^.cpf := cpf;
|
||||||
bool:boolean;
|
novo^.prox := nil;
|
||||||
|
atual:= cpfs[doisDigitos];
|
||||||
|
ant:=nil;
|
||||||
|
while (atual <> nil) and (atual^.cpf < cpf) do
|
||||||
|
begin
|
||||||
|
ant := atual;
|
||||||
|
atual := atual^.prox;
|
||||||
|
end;
|
||||||
|
if ant = nil then
|
||||||
|
begin
|
||||||
|
novo^.prox := cpfs[doisDigitos];
|
||||||
|
cpfs[doisDigitos] := novo;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
novo^.prox := atual;
|
||||||
|
ant^.prox := novo;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
writeln('CPF INVALIDO');
|
||||||
|
end;
|
||||||
|
end;
|
||||||
begin
|
begin
|
||||||
readln(cpf);
|
readln(cpf);
|
||||||
inserirCPF(hash,cpf);
|
inserirCPF(hash,cpf);
|
||||||
|
|||||||
Reference in New Issue
Block a user