Contar quantiade de digitos em um arquivo txt
18/12/2015
0
Vou abrir um arquivo txt.
04 11 13 37 41 56 = 0,1,3,4,5,6,7 (7 digitos)
04 13 15 23 42 57 = 0,1,2,3,4,5,7 (7 digitos)
13 22 23 27 37 57 = 1,2,3,5,7 (5 digitos)
11 22 23 27 42 56 = 1,2,3,4,5,6,7 (7 digitos)
11 15 22 27 37 41 = 1,2,3,4,7 (5 digitos)
Abri o arquivo e pesquisa e contar a quantidade de dígitos e separar os que tem 7 a lógica eh essa,
alguém pode me dar uma ideia ou montar algum aplicativo.
Saudações
Grato
Josenyl Cesar
Post mais votado
06/01/2016
procedure TForm1.btn1Click(Sender: TObject); var arq: TStrings; lidos: array of Byte; lidosStr: string; lido: Boolean; x, y, z, i: integer; begin try // abrindo o arquivo arq := TStringList.Create; arq.LoadFromFile('numeros.txt'); // lendo as linhas for x := 0 to arq.Count - 1 do begin z := 0; SetLength(lidos, 0); // lendo os digitos for y := 1 to Length(arq[x]) do begin // lendo digitos entre 0 e 9 if StrToIntDef(arq[x][y], -1) in [0..9] then begin lido := False; // verificando se o digito ja foi lido for i := 0 to Length(lidos) - 1 do if StrToInt(arq[x][y]) = lidos[i] then begin lido := True; Break; end; // guardando digito lido pra não ler novamente if not lido then begin SetLength(lidos, Length(lidos) + 1); lidos[Length(lidos) - 1] := StrToInt(arq[x][y]); // incrementando quantidade de digitos diferentes Inc(z); end; end; end; lidosStr := ''; // jogando digitos lidos em string pra exibir apenas for i := 0 to Length(lidos)-1 do lidosStr := lidosStr + IntToStr(lidos[i]) + ';'; arq[x] := arq[x] + ' = ' + IntToStr(z) + ' digitos ('+lidosStr+')'; end; ShowMessage(arq.Text); finally arq.Free; end; end;
Raylan Zibel
Mais Posts
04/01/2016
Douglas
Certo, mas ao abrir o arquivo digamos que tenha o exemplo abaixo:
04 11 13 37 41 59 = 0,1,3,4,5,7 (6 dígitos)
Neste caso, seriam 6 dígitos, pois o nove está fora da faixa de 0 à 7? Outra coisa, poderia exemplificar como o teu arquivo txt é montado?
05/01/2016
Josenyl Cesar
se fosse assim exemplo: 04 11 13 37 41 57 = 0,1,3,4,5,7 (6 digitos)
Deu pra entender,
Qualquer duvida
Estou aqui na area.
abraço
05/01/2016
Wazowski
05/01/2016
Josenyl Cesar
Saudações
06/01/2016
Raylan Zibel
Você quer saber a quantidade de dígitos diferentes em cada linha?
06/01/2016
Josenyl Cesar
Grato
06/01/2016
Raylan Zibel
procedure TForm1.btn1Click(Sender: TObject); var arq: TStrings; lidos: array of Byte; lidosStr: string; lido: Boolean; x, y, z, i: integer; begin try arq := TStringList.Create; arq.LoadFromFile('numeros.txt'); for x := 0 to arq.Count - 1 do begin z := 0; SetLength(lidos, 0); for y := 1 to Length(arq[x]) do begin if StrToIntDef(arq[x][y], -1) in [0..9] then begin lido := False; for i := 0 to Length(lidos) - 1 do if StrToInt(arq[x][y]) = lidos[i] then begin lido := True; Break; end; if not lido then begin SetLength(lidos, Length(lidos) + 1); lidos[Length(lidos) - 1] := StrToInt(arq[x][y]); Inc(z); end; end; end; lidosStr := ''; for i := 0 to Length(lidos)-1 do lidosStr := lidosStr + IntToStr(lidos[i]) + ';'; arq[x] := arq[x] + ' = ' + IntToStr(z) + ' digitos ('+lidosStr+')'; end; ShowMessage(arq.Text); finally arq.Free; end; end;
Dá pra melhorar, claro...
Clique aqui para fazer login e interagir na Comunidade :)