var result : integer // à banir c'est une régle, une obligation
function test(s: string) : Integer; begin result := 0; end;
program Test; {$APPTYPE CONSOLE} type ComLet = packed record NbCar : Integer;//nombre de caractère dans la phrase NbLetMin : Integer;//nombre de lettre minuscule NbLetMaj : Integer;//nombre de lettre majuscule end; var Phrase : string; Lettre : Char; ResLet : ComLet; function DownCase(Ch: WideChar): WideChar;//majuscule vers minuscule begin Result := Ch; if Result in ['A'..'Z'] then Dec(Result, Ord('A') - Ord('a')); end; function nbLettre(APhrase: string; ALettre: Char): ComLet; var X : Integer; C : PWideChar; begin Result.NbCar := 0; Result.NbLetMin := 0; Result.NbLetMaj := 0; C := Pointer(APhrase); for X := 0 to Length(APhrase) -1 do begin if C^ in ['A'..'Z','a'..'z'] then begin Inc(Result.NbCar); if DownCase(ALettre) = C^ then Inc(Result.NbLetMin); if UpCase(ALettre) = C^ then Inc(Result.NbLetMaj); end; Inc(C); end; end; begin Write('Entrez une phrase : '); Readln(Phrase); Write('Entrez une lettre : '); Readln(Lettre); ResLet := nbLettre(Phrase, Lettre); Writeln('Il y a : ', ResLet.NbCar, ' lettres dans la phrase :" ', Phrase, ' ".'); Writeln('Dans cette phrase, il y a ', ResLet.NbLetMin, ' lettres minuscule " ', DownCase(Lettre),' ".'); Writeln('Dans cette phrase, il y a ', ResLet.NbLetMaj, ' lettres majuscule " ', UpCase(Lettre),' ".'); Readln; end.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionfunction test(s:string):integer; begin result := length(s); end;
program Project1; {$APPTYPE CONSOLE} uses SysUtils; type TPhraseAnalysis = packed record Spaces : integer; UpChars : integer; LowChars : integer; Numbers : integer; Specials : integer; Length : integer; IsUnicode : boolean; ATUStrict : packed array[Char] of integer; ATU : packed array[Char] of integer; end; procedure PhraseAnalysisReset(var aPA: TPhraseAnalysis); var C: char; begin aPA.Spaces := 0; aPA.UpChars := 0; aPA.LowChars := 0; aPA.Numbers := 0; aPA.Specials := 0; aPA.Length := 0; for C := low(char) to high(char) do begin aPA.ATUStrict[C] := 0; aPA.ATU[C] := 0; end; end; function PhraseAnalyze(const aPhrase: string): TPhraseAnalysis; var N: integer; C,uC,lC: char; begin PhraseAnalysisReset(result); result.IsUnicode := SizeOf(Char) <> 1; result.Length := Length(aPhrase); for N := 1 to result.Length do begin C := aPhrase[N]; uC := upperCase(C)[1]; lC := lowerCase(C)[1]; inc(result.ATUStrict[C]); if uC <> lC then begin inc(result.ATU[uC]); inc(result.ATU[lC]); end else inc(result.ATU[C]); case aPhrase[N] of '0'..'9' : inc(result.Numbers); ' ' : inc(result.Spaces); 'A'..'Z' : inc(result.UpChars); 'a'..'z' : inc(result.LowChars); else inc(result.Specials); end; end; end; const TestPhrase = '0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ?./§,;:!ù*^$¨£%µ&é'; TestChar = 'a'; TestLettre = 'a'; UnicodeResponse : array[boolean] of string = ('non','oui'); var PA : TPhraseAnalysis; begin PA := PhraseAnalyze(TestPhrase); writeln( format( 'Taille de la phrase : %d caracteres'+#13#10+ ' Espaces : %d'+#13#10+ ' Majuscules : %d'+#13#10+ ' Minuscules : %d'+#13#10+ ' Nombres : %d'+#13#10+ ' Speciaux : %d'+#13#10+ ' Unicode : %s'+#13#10+ ' Le caractere "%s" y apparait %d fois'+#13#10+ ' La lettre "%s" y apparait %d fois', [ PA.Length, PA.Spaces, PA.UpChars, PA.LowChars, PA.Numbers, PA.Specials, UnicodeResponse[PA.IsUnicode], TestChar, PA.ATUStrict[TestChar], TestLettre, PA.ATU[TestLettre] ] ) ); readLn; end.