hdu 1716 排列2(水题)

来源:互联网 发布:linux获取文件行数 编辑:程序博客网 时间:2024/06/05 09:04
排列2


Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6084    Accepted Submission(s): 2332




Problem Description
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

 


#include <limits.h>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <algorithm>#include <iostream>#include <iterator>#include <sstream>#include <queue>#include <stack>#include <string>#include <vector>#include <set>//#define ONLINE_JUDGE#define eps 1e-6#define INF 0x7fffffff                                          //INT_MAX#define inf 0x3f3f3f3f                                          //int??????????????????#define FOR(i,a) for((i)=0;i<(a);(i)++)                          //[i,a);#define MEM(a) (memset((a),0,sizeof(a)))#define sfs(a) scanf("%s",a)#define sf(a) scanf("%d",&a)#define sfI(a) scanf("%I64d",&a)#define pf(a) printf("%d\n",a)#define pfI(a) printf("%I64d\n",a)#define pfs(a) printf("%s\n",a)#define sfd(a,b) scanf("%d%d",&a,&b)#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)#define for1(i,a,b) for(int i=(a);i<b;i++)#define for2(i,a,b) for(int i=(a);i<=b;i++)#define for3(i,a,b)for(int i=(b);i>=a;i--)#define MEM1(a) memset(a,0,sizeof(a))#define MEM2(a) memset(a,-1,sizeof(a))#define MEM3(a) memset(a,0x3f,sizeof(a))#define MEMS(a) memset(a,'\0',sizeof(a))#define LL __int64const double PI = acos(-1.0);template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }using namespace std;template<class T>T Mint(T a, T b, T c) {    if (a>b) {        if (c>b)            return b;        return c;    }    if (c>a)        return a;    return c;}template<class T>T Maxt(T a, T b, T c) {    if (a>b) {        if (c>a)            return c;        return a;    }    else if (c > b)        return c;    return b;}const int maxn=105;int T,n,m;int a[4],b[maxn];int main() {#ifndef ONLINE_JUDGEfreopen("test.in","r",stdin);freopen("test.out","w",stdout);#endifint k=0;while(~scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])){if(!a[0]&&!a[1]&&!a[2]&&!a[3]) break;if(k) putchar(10);k=0;sort(a,a+4);do{if(a[0]!=0){b[k++]=a[0]*1000+a[1]*100+a[2]*10+a[3];}}while(next_permutation(a,a+4));for1(i,0,k){if(i==k-1) pf(b[i]);else if(b[i]/1000==b[i+1]/1000) printf("%d ",b[i]);else pf(b[i]);}}return 0;}


0 0
原创粉丝点击