next_permutation 函数的应用
来源:互联网 发布:windows update官网 编辑:程序博客网 时间:2024/06/05 01:05
H - 排列2
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
Ray又对数字的列产生了兴趣:
现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。
现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。
Input
每组数据占一行,代表四张卡片上的数字(0<=数字<=9),如果四张卡片都是0,则输入结束。
Output
对每组卡片按从小到大的顺序输出所有能由这四张卡片组成的4位数,千位数字相同的在同一行,同一行中每个四位数间用空格分隔。
每组输出数据间空一行,最后一组数据后面没有空行。
每组输出数据间空一行,最后一组数据后面没有空行。
Sample Input
1 2 3 41 1 2 30 1 2 30 0 0 0
Sample Output
1234 1243 1324 1342 1423 14322134 2143 2314 2341 2413 24313124 3142 3214 3241 3412 34214123 4132 4213 4231 4312 43211123 1132 1213 1231 1312 13212113 2131 23113112 3121 32111023 1032 1203 1230 1302 13202013 2031 2103 2130 2301 23103012 3021 3102 3120 3201 3210
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){ int a[5],tag=0; while(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])){ if(a[0]==0 && a[1]==0 && a[2]==0 && a[3]==0) break; if(tag) printf("\n"); tag=1; int flag=1,tmp; do{ if(a[0]==0) continue; if(flag){ printf("%d%d%d%d",a[0],a[1],a[2],a[3]); //flag只是控制第一次输出没空格 flag=0; }else if(tmp==a[0]) printf(" %d%d%d%d",a[0],a[1],a[2],a[3]); else printf("\n%d%d%d%d",a[0],a[1],a[2],a[3]); tmp=a[0]; }while(next_permutation(a,a+4)); //每次输出当前字典序的下一个序列 printf("\n"); } return 0;}
0 0
- next_permutation函数的应用
- next_permutation 函数的应用
- POJ1833 next_permutation函数应用
- 排列 next_permutation的应用
- hdu1027 next_permutation的应用
- 全排列(STL之next_permutation函数的应用)
- next_permutation的函数
- next_permutation函数的使用
- STL的next_permutation函数
- HOJ 1191 (next_permutation()的应用)
- next_permutation的简单应用HDU1207
- 关于next_permutation函数的模拟!
- c++ next_permutation()函数的使用
- next_permutation应用
- Nyoj-366 D的小L (全排列函数next_permutation的应用)
- next_permutation函数
- next_permutation函数
- next_permutation()函数
- OC4J Configuration issue. /u01...dbhome_1/oc4j/j2ee/OC4J_DBConsole_orcl-db-01_orcl not found.
- 记。
- lds连接脚本
- 机器学习(周志华) 参考答案 第九章 聚类
- LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- next_permutation 函数的应用
- 出塞
- 【机房收费系统】多步OLE DB 操作产生错误
- 数据结构实验之排序七:选课名单
- c#之面向对象的个人理解
- 使用-webkit-box-flex 实现 一半文本显示完全 一半文本宽度自适应
- poj2387 Dijkstra模板程序
- 汇编语言基础--嵌入式
- 图结构练习——BFS——从起始点到目标点的最短步数