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 #include<algorithm>
3 using namespace std;
4
5 int main()
6 {
7 int num[4];
8 int x=0;
9 while(1)
10 {
11 if(x)cout<<endl;//每组数据间空一行
12 x=1;
13 int c=0;
14 for(int i=0;i<4;i++)
15 {
16 cin>>num[i];
17 if(num[i]==0)c++;
18 }
19 if(c==4)break;//输入0的个数为4结束循环
20
21 sort(num,num+4);//排序得到最小四位数
22 while(num[0]==0)
23 {
24 next_permutation(num,num+4);//4位数千位不能为0
25 }
26 int k=10;
27 do
28 {
29 if(k==num[0])
30 cout<<" ";
31 else if(k!=10)//k!=num[0]换行,第一次输出不换行
32 cout<<endl;
33 for(int i=0;i<4;i++)
34 cout<<num[i];
35 k=num[0];
36 }while(next_permutation(num,num+4));
37 cout<<endl;//最后一个四位数输出后换行
38 }
39 return 0;
40 }

STL练习-排列2的更多相关文章

  1. C++STL 之排列

    固然我们可以自己使用递归编写全排列程序,但是既然STL里面已将有了这个功能为什么不直接用呢,下面就写一下直接使用C++ STL生成全排序的程序 函数名:next_permutation 包含头文件:a ...

  2. nyoj------擅长排列的小明

    擅长排列的小明 时间限制:1000 ms  |           内存限制:65535 KB 难度:4   描述 小明十分聪明,而且十分擅长排列计算.比如给小明一个数字5,他能立刻给出1-5按字典序 ...

  3. POJ-2718

    Smallest Difference Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12158   Accepted: 3 ...

  4. nyist oj 19 擅长排列的小明(dfs搜索+STL)

    擅长排列的小明 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描写叙述 小明十分聪明.并且十分擅长排列计算.比方给小明一个数字5,他能立马给出1-5按字典序的全排列,假设你想 ...

  5. 枚举所有排列-STL中的next_permutation

    枚举排列的常见方法有两种 一种是递归枚举 另一种是STL中的next_permutation //枚举所有排列的另一种方法就是从字典序最小排列开始,不停的调用"求下一个排列"的过程 ...

  6. suseoj 1208: 排列问题 (STL, next_permutation(A.begin(), A.end()))

    1208: 排列问题 时间限制: 1 Sec  内存限制: 128 MB提交: 2  解决: 2[提交][状态][讨论版][命题人:liyuansong] 题目描述 全排列的生成就是对于给定的字符集或 ...

  7. C++ STL next_permutation(快速排列组合)

    排列组合必备!! https://blog.csdn.net/bengshakalakaka/article/details/78515480

  8. HDU 1027(数字排列 STL)

    题意是求 n 个数在全排列中的第 m 个序列. 直接用 stl 中的 next_permutation(a, a+n) (这个函数是求一段序列的下一个序列的) 代码如下: #include <b ...

  9. hdu1716排列2(stl:next_permutation+优先队列)

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  10. poj 1833 排列 STL 全排列公式

    排列 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15173   Accepted: 6148 Description 题 ...

随机推荐

  1. 将含两列的csv文件生成二维矩阵

    gen_diea=pd.read_csv('../data/ddg_data/diea-gene.csv', header=None, names=['diease','gene']) #生成关联矩阵 ...

  2. python checklist

    1. 常用模块:subprocess, requests, paramekio, traceback, argparse, numpy, pandas 2. 赋值传递和引用传递 python是赋值传递 ...

  3. 【Selenium IDE】下载安装Chrome和Firefox插件IDE ide了解就行 不是重点 重点是写脚本

    下载安装Chrome和Firefox插件IDE 1.Chrome的IDE安装(1)由于chrome的限制所以提供了一个小方法:链接: https://www.crx4chrome.com/crx/77 ...

  4. 我和Java这些年的故事(五)

    时光荏苒,我来到了IBM.和慕名已久的WebSphere Application Server(WAS)打起了交道. 之前我搞过Weblogic,对应用服务器的特性有了一定的了解.但WAS无疑更为庞大 ...

  5. ICPC2020上海B - Mine Sweeper II

    思维 [B-Mine Sweeper II_第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(上海)(重现赛)@hzy0227 (nowcoder.com)](https://codeforc ...

  6. Access denied You do not have access to chat.openai.com. The site owner may have set restrictions that prevent you from accessing the site.解决办法

    报错 Access denied You do not have access to chat.openai.com. The site owner may have set restrictions ...

  7. Gin加载history模式下打包后的Vue文件,刷新找不到页面404

    import ( "io/ioutil" "github.com/gin-contrib/static" "github.com/gin-gonic/ ...

  8. QDateEdit

    self.dateEdit.setCalendarPopup(True) # 日历增加 # 日历转化位str类型begintime = self.dateEdit.dateTime().toStrin ...

  9. golang实现请求cloudflare修改域名A记录解析

    现在有些DNS解析要收费,国内的几个厂商需要实名制.下面给出golang请求cloudflare修改域名A记录解析的代码. 准备工作: 在域名购买服务商处,将dns解析服务器改为cloudflare的 ...

  10. element 表格show-overflow-tooltip的属性设置样式

    在style标签中不要加scoped .el-tooltip__popper { max-width: 60% !important; } .el-tooltip__popper, .el-toolt ...