zoukankan      html  css  js  c++  java
  • [CODEVS1294]全排列

    题目描述 Description

    给出一个n, 请输出n的所有全排列

    输入描述 Input Description

    读入仅一个整数n   (1<=n<=10)

    输出描述 Output Description

    一共n!行,每行n个用空格隔开的数,表示n的一个全排列。并且按全排列的字典序输出。

    样例输入 Sample Input

    3

    样例输出 Sample Output

    1 2 3

    1 3 2

    2 1 3

    2 3 1

    3 1 2

    3 2 1

    var n:longint;
        a:array[1..100]of longint;
        p:array[1..100] of boolean;
    procedure print;
    var i:longint;
    begin
      for i:=1 to n do write(a[i],' ' );
      writeln;
    end;
    procedure try(k:longint);
    var  i:longint;
    begin
      if k=n+1 then print
      else
       for i:=1 to n do
        if p[i] then
         begin
          a[k]:=i;
          p[i]:=false;
          try(k+1);
          p[i]:=true;
         end;
    end;
    begin
      read(n);
      fillchar(p,sizeof(p),true);
      fillchar(a,sizeof(a),0);
      try(1);
    end.
  • 相关阅读:
    iOS 远程推送
    iOS 本地推送
    iOS 循环利用的注意事项
    iOS 通知代理执行代理方式时,代理为nil的解决办法
    iOS SSZipArchive
    iOS PushMebaby
    Objective
    Objective
    Objective
    Objective
  • 原文地址:https://www.cnblogs.com/yangqingli/p/4709289.html
Copyright © 2011-2022 走看看