回 帖 发 新 帖 刷新版面

主题:排列

program ex_1;                                                               
const                                                                       
 m=10;                                                                      
var                                                                         
 a:array[1..m] of char;                                                     
 z:integer;                                                                 
                                                                            
procedure swap(aa,bb:integer);                                              
var                                                                         
 cc:char;                                                                   
begin                                                                       
 cc:=a[aa];                                                                 
 a[aa]:=a[bb];                                                              
 a[bb]:=cc;                                                                 
end;                                                                        
                                                                            
procedure ment(u:integer);                                                  
var                                                                         
 o:integer;                                                                 
begin                                                                       
 if u=0 then begin for o:=1 to m do write(a[o]);writeln end                 
 else for o:=1 to u do                                                      
          begin                                                             
           swap(m-u+o,m+1-u);                                               
           ment(u-1);                                                       
           swap(m-u+o,m+1-u);                                               
          end;                                                              
end;                                                                        
                                                                            
begin                                                                       
 for z:=1 to m do                                                           
     begin                                                                  
      a[z]:=chr(z+64);                                                      
     end;                                                                  
 ment(m);                                                                   
 readln                                                                     
end.

回复列表 (共2个回复)

沙发

是输出全排列吗?

板凳

说明白点,想干嘛呀?

我来回复

您尚未登录,请登录后再回复。点此登录或注册