排列2 + stl函数+ next_permutation()
来源:互联网 发布:炉石淘宝买卡包安全吗 编辑:程序博客网 时间:2024/06/06 01:22
排列2
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3114 Accepted Submission(s): 1222
Problem Description
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/*思路:调用next_permutation()函数,细节输出格式*/#include<iostream>#include<algorithm>using namespace std ;int main(){int a[4] ,flag = 0 ;while(cin>>a[0]>>a[1]>>a[2]>>a[3]&&(a[0]||a[1]||a[2]||a[3])){if(flag){cout<<endl;}elseflag = 1;sort(a,a+4);for(int i = 0 ; i<4; i++)if(a[i])break;if(i>=4)i = 0 ;int cnt = 0 ,mark = a[i];do{if(a[0]==0)continue ;if(mark!=a[0]){mark = a[0] ;cout<<endl;cnt = 0 ;}if(cnt)cout<<" ";elsecnt = 1;cout<<a[0]<<a[1]<<a[2]<<a[3];}while(next_permutation(a,a+4));cout<<endl;}return 0;}
- 排列2 + stl函数+ next_permutation()
- hdu1027 全排列(STL函数next_permutation)
- HDU 1716 排列2 (stl,next_permutation)
- 生成字典序排列(C++ STL) next_permutation函数
- STL之 next_permutation函数{(全排列)按字典序!!!!!}
- POJ 1833 排列(STL之next_permutation函数)
- STL之next_permutation() 全排列函数
- STL中全排列函数 next_permutation
- STL中的全排列next_permutation函数
- HDOJ 1716 排列2(next_permutation函数)
- HDOJ 1716 排列2(next_permutation函数)
- hdu1716排列2(stl:next_permutation+优先队列)
- 全排列函数 next_permutation()
- next_permutation函数(全排列)
- next_permutation函数(全排列)
- poj 题目1883 排列(STL----next_permutation)
- STL(next_permutation)poj 1833:排列
- STL next_permutation 全排列
- cookie 和session 的区别详解
- Forward函数和sendRedirect函数
- Algorithm notes
- cocos2d-x 中 Sqlite3 事务(Transaction)操作
- 文件 I/O——open函数
- 排列2 + stl函数+ next_permutation()
- Spring事务杂谈
- UVaOJ674 - Coin Change
- 算法竞赛入门经典 快速排序和并归排序
- Oracle中常用的to_Char用法详解(有FMT的详细列表)
- centos6.2使用yum安装lamp
- poj_1321_棋盘问题(DFS)
- vba word 下载网络上的文件
- 计算机专业推荐书籍