HDUoj
来源:互联网 发布:学习ios软件 编辑:程序博客网 时间:2024/06/11 21:02
Description
Ray又对数字的列产生了兴趣:
现有四张卡片,用这四张卡片能排列出很多不同的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_pertation()
注意空格与换行问题
AC代码
#include <bits/stdc++.h>using namespace std;const int N = 1e4;int arr[5], brr[N];int main(){ for(int i = 0;i < 4; i++) cin>>arr[i]; while(true) { if(arr[0]+arr[1]+arr[2]+arr[3]+arr[4]==0) break; sort(arr,arr+4); int k = arr[0]; if(arr[0]!=0) printf("%d%d%d%d",arr[0],arr[1],arr[2],arr[3]); while(next_permutation(arr,arr+4)) { if(arr[0]==k&&arr[0]) printf(" %d%d%d%d",arr[0],arr[1],arr[2],arr[3]); else { if(arr[0]) { if(k) printf("\n"); printf("%d%d%d%d",arr[0],arr[1],arr[2],arr[3]); } k = arr[0]; } } printf("\n"); for(int i = 0;i < 4; i++) cin>>arr[i]; if(arr[0]+arr[1]+arr[2]+arr[3]+arr[4]) printf("\n"); }return 0;}
阅读全文
0 0
- HDUOJ
- HDUoj
- HDUOJ 2050
- HDUOJ 2018
- HDUOJ 2069
- HDUOJ 1303
- HDUOJ 2031
- HDUOJ 2047
- HDUOJ 2089
- hduoj 1708
- hduoj 2031
- hduoj 2032
- hduoj 1062
- HDUOJ 1039
- HDUOJ lines
- HDUOJ入门
- HDUOJ 水果
- hduoj 分类
- short text conversation: neural network
- 8.15 NP完全问题证明
- 新买的stm8使用IAR烧录出错问题解决
- 安卓自定义控件
- 提高篇第二十一讲——有序数组中插入数据
- HDUoj
- 最新PADS无模命令
- Windows编程:计时器的创建
- Ubuntu常用命令合集
- JSP数据交互(二)
- Java后台之路(09)-Servlet
- 网络流&费用流总结
- javaweb之jsp之out隐式对象原理
- org.hibernate.exception.GenericJDBCException: could not execute statement at org.hibernate.exceptio