Cho một văn bản chứa trong một file. Bạn hãy viết chương trình tính tỉ lệ các nguyên âm có mặt trong văn bản theo thứ tự của bảng chữ cái.Định nghĩa các nguyên âm là: A,E, I, O, U, Y
Dữ liệu vào:
file NGUYENAM.INP gồm nhiều dòng chứa các ký tự của
văn bản
Dữ liệu ra:
file NGUYENAM.OUT mỗi dòng ghi ký tự và tỷ lệ % (lấy đến
4 chữ số thập phân) của các nguyên âm.
var
S,St:string;
j,k,a,e,i,o,u,y:longint;
f1,f2:text;
{-------------------------------------------------}
function
viethoa(S:string):string;
var
St:string;
begin
St:='';
for
i:=1 to length(S) do St:=St+upcase(S[i]);
viethoa:=St;
end;
{-------------------------------------------------}
function
tile(n:longint):real;
var
a:real;
begin
k:=length(S);
a:=n/k*100;
tile:=a;
end;
{-------------------------------------------------}
Begin
assign(f1,'tile.inp');reset(f1);
assign(f2,'tile.out');rewrite(f2);
readln(f1,St);
S:=viethoa(St);
a:=0;e:=0;i:=0;o:=0;u:=0;y:=0;
for
j:=1 to length(S) do
if
S[j]='A' then inc(a) else
if S[j]='E'
then inc(e)
else if
S[j]='I' then inc(i)
else if
S[j]='O' then inc(o)
else if
S[j]='U' then inc(u)
else
if S[j]='Y' then inc(y);
writeln(f2,'A
',tile(a):2:4,'%');
writeln(f2,'E
',tile(e):2:4,'%');
writeln(f2,'I
',tile(i):2:4,'%');
writeln(f2,'O
',tile(o):2:4,'%');
writeln(f2,'U
',tile(u):2:4,'%');
writeln(f2,'Y
',tile(y):2:4,'%');
close(f1);close(f2);
end.
Sign up here with your email
ConversionConversion EmoticonEmoticon