Ahojte,
mam udelat program do skoly, ale absolutne si s tim nevim rady.
Ten program ma delat asi toto:
Uzivatel ho spusti a napise libovolny text. Program mu nasladne vypise kolik je tam jakych pismenek
Napr. kolikrat je tam A, B, C, D apod. Nerozlisuje mala a velka pismena a uzivatel pise text bez hacku a carek a cisel.
Program se ma vytvorit podle typu pole jednodimenzionalniho.
Poradite nekdo jak by to melo vypadat prosim? Jsem zoufala :(
Fórum › Pascal
Skolni ukol...

program Ladenka;
uses
SysUtils;
type TPismena = array ['A'..'Z'] of Integer;
var pismena: TPismena;
veta:String;
i:Integer;
c:char;
begin
for c:='A' to 'Z' do pismena[c] := 0; {vynuluje pole}
Write('Zadej vetu: '); Readln(veta); {Nacte vetu}
for i:=1 to Length(veta) do begin
c := UpCase(veta[i]); {Prevede na velke}
if(c in ['A'..'Z']) then {pokud je to pismeno, jen at se nepohybujeme mimo rozsah pole}
Pismena[c] := Pismena[c]+1; {zvysi pocet vyskytu pismana}
end;
writeln('Pismeno',#9,'Pocet'); {#9 - znak tabulatoru}
writeln('-------------------');
for c := 'A' to 'Z' do
if(Pismena[c] <> 0)then
writeln(c + #9, Pismena[c]); {Zameyi tisku ynaku , ktere v textu vubec nebyly}
readln; {ceka na enter}
{ TODO -oUser -cConsole Main : Insert code here }
end.
Až na třídění to je jednoduché...
var s:string;
p:array[0..255] of byte; {kolik kterych znaku jsme nasli}
a:integer;
c:char;
b:byte;
i:integer;
d:char;
begin
writeln('Zadej text:');
readln(s);
for a:=1 to Length(s) do {abychom vyhoveli pozadavku, ze se nerozlisuji}
s[a]:=UpCase(s[a]); {mala a velka pismena, tak vse prevedeme na velka}
{Ted vynuluju pole pro pocet znaku}
for a:=0 to 255 do p[a]:=0;
for a:=1 to Length(s) do {pismeno po pismenu projed cely retezec}
begin
c:=s[a]; {A-ty znak dame do C}
b:=byte(c); {Takto ziskam ciselny kod znaku C}
p:=p+1; {pripoctu pocet nalezenych znaku s kodem B}
end;
{Ted zname cetnost jednotlivych znaku}
{Napred je vypisu nesetridene...}
for a:=1 to 255 do
if p[a]>0 then
writeln('Znak "',char(a),'" byl ',p[a],' krat.');
readln;
{Pohodlnejsi by ale bylo vypis setridit...}
repeat
i:=0;
for b:=0 to 255 do
if p>i then
begin
i:=p;
d:=char(b);
end;
b:=byte(d);
p:=0;
if i>0 then writeln('Znak "',d,'" byl ',i,' krat.');
until i=0;
readln;
end.

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 21 hostů
Podobná vlákna
Školní úkol - výpočet kombinatorických funkcí — založil Nohy
Školní projekt — založil Asimka
Školní práce v C — založil Marek
školní práce — založil Jan Malý
Školní projekt — založil Honza
Moderátoři diskuze