88 lines
2.3 KiB
ObjectPascal
88 lines
2.3 KiB
ObjectPascal
program cpfs;
|
|
|
|
type
|
|
TCPF = ^ptcpf;
|
|
ptcpf = record
|
|
cpf : string;
|
|
prox : TCPF;
|
|
end;
|
|
THash = array[0..99] of TCPF;
|
|
|
|
|
|
function validarCPF(var cpf:string):boolean;
|
|
var
|
|
i, soma, dig1, dig2:integer;
|
|
begin
|
|
soma:=0;
|
|
for i:=1 to 9 do
|
|
//ord('0')=48... ord('1')=49... dai -48 vira 0... *11-i, vai decrementando, *9, *8, *7...
|
|
soma:=soma+(Ord(cpf[i])-48)*(11-i);
|
|
|
|
dig1 := 11 - (soma mod 11); //digito 1 pega a sobra da divisao bla bla
|
|
if (dig1 = 10) or (dig1 = 11) then
|
|
dig1 := 0;
|
|
|
|
|
|
soma := 0;
|
|
for i := 1 to 10 do
|
|
soma := soma + (Ord(cpf[i])-48)*(12-i);
|
|
|
|
dig2 := 11 - (soma mod 11);
|
|
if (dig2 = 10) or (dig2 = 11) then
|
|
gitea@10.0.0.42:iTakinn/cpfs_pascal.git dig2 := 0;
|
|
|
|
ValidarCPF :=
|
|
(dig1=(Ord(cpf[10])-48)) and (dig2=(Ord(cpf[11])-48));
|
|
|
|
end;
|
|
|
|
|
|
procedure inserirCPF(var cpfs:THash; var cpf:string);
|
|
var
|
|
i, pos:integer;
|
|
novo, atual, ant:TCPF;
|
|
begin
|
|
if validarCPF(cpf) then
|
|
begin
|
|
pos:=(Ord(cpf[10])-48)*10 + (Ord(cpf[11])-48); //esse ngocio pega os digitos verificadores, gpt ajudou, transformar string em int é pesadelo
|
|
new(novo);
|
|
if novo = nil then
|
|
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;
|
|
|
|
|
|
|
|
|
|
var
|
|
hash: THash;
|
|
cpf:string;
|
|
bool:boolean;
|
|
begin
|
|
readln(cpf);
|
|
inserirCPF(hash,cpf);
|
|
end. |