排列2

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

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 <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
set<int>s[];
int a[];
int main()
{
int ok=;
while(scanf("%d%d%d%d",&a[],&a[],&a[],&a[])&& (a[],a[],a[],a[]))
{
if(ok) printf("\n");
ok++;
for(int i=;i<;i++) s[i].clear();
do{
if(a[]==) continue;
int ans=;
for(int i=;i<;i++)
{
ans=ans*+a[i];
}
s[a[]].insert(ans);
}while(next_permutation(a,a+));
for(int i=;i<;i++)
{
if(s[i].size()==) continue;
bool flag=true;
for(set<int>::iterator it=s[i].begin();it!=s[i].end();it++)
{
if(!flag) printf(" ");
printf("%d",*it);
flag=false;
}
printf("\n");
}
}
return ;
}

最新文章

  1. ip扫描
  2. Reflector、reflexil、De4Dot、IL指令速查表
  3. hdu acmsteps 2.1.3 Cake
  4. Nuget程序包 使用log4net
  5. Unity安卓连接profile调试
  6. chrome的timeline的问题?
  7. max key length is 1000 bytes
  8. linux中权限对文件和目录的作用
  9. [Swift]LeetCode79. 单词搜索 | Word Search
  10. 【Android】打开本地的html文件
  11. 使用css设置三角形
  12. jsp小测试--猜大小
  13. Android面试基础(一)IOC(DI)框架(ViewUtils)讲解_反射和自定义注解类
  14. IDEA导入JAR的源代码
  15. 如何快速学好Shell脚本? 转
  16. 源码分析四(HashMap与HashTable的区别 )
  17. POJ 3630 Phone List(字符串前缀重复)题解
  18. [转帖] 红帽8.0 beta版本发布 内核新版本 4.18
  19. Mysql的with rollup分组统计功能(5.1以上版本)
  20. B. Mike and Fun---cf548B(暴力求解)

热门文章

  1. xargs---组合命令的工具
  2. HNU 12961 BitTorrent DP
  3. 四 过滤模式 map Only - 作业完成 bloomFilter、top10、去重
  4. C语言函数--E
  5. hdu(1069)——Monkey and Banana(LIS变形)
  6. BZOJ 3781 莫队
  7. 初学Larevel 2014-08-21 11:24 90人阅读 评论(0) 收藏
  8. iRedMail邮件系统配置简易视频安装教程
  9. Ionic2集成ngx-datatable,ng2-tree第三方控件.md
  10. android学习笔记五。2、其他组件