Nhập sâu S đếm số lần lượt số lần xuất hiện mỗi kí tự trong sâu S ( không phân biệt chữ,số) vd : S = MADAM M : 2 A : 2 D : 1 C

By Bella

Nhập sâu S đếm số lần lượt số lần xuất hiện mỗi kí tự trong sâu S ( không phân biệt chữ,số)
vd : S = MADAM
M : 2
A : 2
D : 1
Cần gấp ạ !

0 bình luận về “Nhập sâu S đếm số lần lượt số lần xuất hiện mỗi kí tự trong sâu S ( không phân biệt chữ,số) vd : S = MADAM M : 2 A : 2 D : 1 C”

  1. 1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    uses crt;

    var s:string[30];

    ch,x:char;

    i:byte;

    dem:array[‘A’..’Z’]of byte;

    BEGIN

    clrscr;

    write(‘Nhap vao xau s=’);

    readln(s);

    for ch:=’A’ to ‘Z’ do dem[ch]:=0;

    for i:=1 to length(s) do

    begin

    x:=upcase(s[i]);

    if (x>=’A’) and (x<='Z')

    then

    dem[x]:=dem[x]+1;

    end;

    for ch:=’A’ to ‘Z’ do

    if dem[ch]<>0 then

    writeln(‘So luong ki tu’,ch,’la’,dem[ch]);

    readln;

    Trả lời

Viết một bình luận