Pagini recente » Cod sursa (job #2071939) | Cod sursa (job #1832342) | Cod sursa (job #2209781) | Cod sursa (job #1415199) | Cod sursa (job #120682)
Cod sursa(job #120682)
var f,g:text;
v:array[1..10000] of integer;
c:array[1..10000] of char;
i,m,nr,n:integer;
s:longint;
j,b:char;
begin
assign (f,'litere.in');reset (f);
assign (g,'litere.out');rewrite (g);
readln (f,n);
n:=0;
while not eof(f) do begin
read (f,b);
if b in['a'..'z'] then begin
inc(n);
c[n]:=b;
v[n]:=n;
end;
end;
nr:=1;
for j:='a' to 'z' do begin
m:=0;
for i:=1 to n do
if c[i]=j then begin
s:=s+v[i]-nr;
inc(nr);
end;
for i:=n downto 1 do begin
v[i]:=v[i]+m;
if c[i]=j then inc(m);
end;
end;
writeln (g,s);
close(f);close(g);
end.