- 4 Tháng năm 2018
- 1,485
- 1,656
- 236
- Vĩnh Phúc
- Trung học cơ sở Lập Thạch
Chắc suất Đại học top - Giữ chỗ ngay!! ĐĂNG BÀI NGAY để cùng trao đổi với các thành viên siêu nhiệt tình & dễ thương trên diễn đàn.
Mã:
var a:array[1..1000000] of int64;
f:array[1..26] of int64;
s:string;
n,i,j:longint;max:int64;
Procedure QS(d,c:int64);
Var
i,j,g:longint;tg:int64;
Begin
i:=d;j:=c;g:=a[(i+j) div 2];
Repeat
While a[i]<g do inc(i);
While a[j]>g do dec(j);
If i<=j then
Begin
tg:=a[i];a[i]:=a[j];a[j]:=tg;
inc(i);dec(j);
End;
Until i>=j;
If i<c then qs(i,c);
If d<j then qs(d,j);
End;
Begin
Assign(input,'freq.inp');reset(input);
Assign(output,'freq.out');rewrite(output);
Read(s);
For i:=1 to 26 do
f[i]:=0;
For i:=1 to length(s) do
Begin
If (s[i]='a') or (s[i]='A') then inc(f[1]);
If (s[i]='b') or (s[i]='B') then inc(f[2]);
If (s[i]='c') or (s[i]='C') then inc(f[3]);
If (s[i]='d') or (s[i]='D') then inc(f[4]);
If (s[i]='e') or (s[i]='E') then inc(f[5]);
If (s[i]='f') or (s[i]='F') then inc(f[6]);
If (s[i]='g') or (s[i]='G') then inc(f[7]);
If (s[i]='h') or (s[i]='H') then inc(f[8]);
If (s[i]='i') or (s[i]='I') then inc(f[9]);
If (s[i]='j') or (s[i]='J') then inc(f[10]);
If (s[i]='k') or (s[i]='K') then inc(f[11]);
If (s[i]='l') or (s[i]='L') then inc(f[12]);
If (s[i]='m') or (s[i]='M') then inc(f[13]);
If (s[i]='n') or (s[i]='N') then inc(f[14]);
If (s[i]='o') or (s[i]='O') then inc(f[15]);
If (s[i]='p') or (s[i]='P') then inc(f[16]);
If (s[i]='q') or (s[i]='Q') then inc(f[17]);
If (s[i]='r') or (s[i]='R') then inc(f[18]);
If (s[i]='s') or (s[i]='S') then inc(f[19]);
If (s[i]='t') or (s[i]='T') then inc(f[20]);
If (s[i]='u') or (s[i]='U') then inc(f[21]);
If (s[i]='v') or (s[i]='V') then inc(f[22]);
If (s[i]='w') or (s[i]='W') then inc(f[23]);
If (s[i]='x') or (s[i]='X') then inc(f[24]);
If (s[i]='y') or (s[i]='Y') then inc(f[25]);
If (s[i]='z') or (s[i]='Z') then inc(f[26]);
qs(1,26);
End;
Write(f[26]);
End.
Đề : Cho 1 xâu s. Tìm tần số lớn nhất của s trong xâu s.
VD : abndhnbsnnbaoooooooooo
out: 10
Em cảm ơn!