• 排列2 HDU


    Ray又对数字的列产生了兴趣: 
    现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。

    Input每组数据占一行,代表四张卡片上的数字(0<=数字<=9),如果四张卡片都是0,则输入结束。 
    Output对每组卡片按从小到大的顺序输出所有能由这四张卡片组成的4位数,千位数字相同的在同一行,同一行中每个四位数间用空格分隔。 
    每组输出数据间空一行,最后一组数据后面没有空行。 
    Sample Input

    1 2 3 4
    1 1 2 3
    0 1 2 3
    0 0 0 0

    Sample Output

    1234 1243 1324 1342 1423 1432
    2134 2143 2314 2341 2413 2431
    3124 3142 3214 3241 3412 3421
    4123 4132 4213 4231 4312 4321
    
    1123 1132 1213 1231 1312 1321
    2113 2131 2311
    3112 3121 3211
    
    1023 1032 1203 1230 1302 1320
    2013 2031 2103 2130 2301 2310
    3012 3021 3102 3120 3201 3210
    依然是自动排序的函数 格式贼烦
     1 #include <iostream>
     2 
     3 using namespace std;
     4 #include<stack>
     5 #include<stdio.h>
     6 #include<math.h>
     7 #include<string.h>
     8 #include<map>
     9 #include<queue>
    10 #include<algorithm>
    11 int main()
    12 {
    13     int a[5];
    14     int flag1=1;
    15     while(cin>>a[0]>>a[1]>>a[2]>>a[3])
    16     {
    17         if(a[0]==0&&a[1]==0&&a[2]==0&&a[3]==0)
    18             break;
    19         if(flag1)
    20         flag1=0;
    21         else
    22             cout<<endl;
    23 
    24         int i=a[0];
    25         sort(a,a+4);
    26         int flag=0,flag2=1;
    27         do
    28         {
    29             if(a[0]==0)
    30             {
    31                 flag2=0;
    32                 flag=1;
    33                 continue;
    34             }
    35             if(i!=a[0])
    36             {
    37 
    38                 i=a[0];
    39                 if(flag)
    40                 {
    41                     flag=0;
    42                     cout<<a[0]<<a[1]<<a[2]<<a[3];
    43                      continue;
    44                 }
    45                 cout<<endl;
    46                 cout<<a[0]<<a[1]<<a[2]<<a[3];
    47                 continue;
    48             }
    49             if(flag2)
    50             {
    51                 flag2=0;
    52                 cout<<a[0]<<a[1]<<a[2]<<a[3];
    53                 continue;
    54             }
    55             cout<<' '<<a[0]<<a[1]<<a[2]<<a[3];
    56         }while(next_permutation(a,a+4));
    57         cout<<endl;
    58     }
    59     return 0;
    60 }
    View Code
  • 相关阅读:
    python 字典
    python set集合
    python封装和解构
    python 内置数据结构 切片
    CPU 上下文切换及案例分析
    怎么理解linux的平均负载及平均负载高后的排查工具
    Linux性能优化
    python 内置数据结构 字符串
    python内置数据结构
    python GC、分支、循环
  • 原文地址:https://www.cnblogs.com/dulute/p/7272537.html
Copyright © 2020-2023  润新知