Подсчет количества различный букв в слове — Pascal(Паскаль)

var s:string;
    r:real;
    i,j,n:integer;
begin
    r:=0;
    readln(s);
    for i:=1 to length(s) do begin
       n:=0;
       for j:=1 to length(s) do begin
          if s[i]=s[j] then inc(n);
       end;
       r:=r+1/n;
    end;
    writeln('количество различных букв = ', r:1:0);
end.

Компиляция и выполнение

Free Pascal Compiler version 2.6.2-8 [2014/01/22] for x86_64                                                                                     
Copyright (c) 1993-2012 by Florian Klaempfl and others                                                                                           
Target OS: Linux for x86-64                                                                                                                      
Compiling main.pas                                                                                                                               
Linking a.out                                                                                                                                    
28 lines compiled, 0.1 sec                                                                                                                       
/usr/bin/ld.bfd: warning: link.res contains output sections; did you forget -T?                                                                  
дом, любимый дом                                                                                                                                 
количество различных букв = 13                                                                                                                   
                                                                                                                                                 
                                                                                                                                                 
...Program finished with exit code 0                                                                                                             
Press ENTER to exit console.            

Leave a Comment

+ 13 = 20