排列2

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

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 <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; int main(){
int a[];
int flot = ;
while(){ int x = ;
for(int i = ; i < ; i++){
scanf("%d", a + i);
x |= a[i];
}
sort(a, a + );
if(!x)break; if(flot)puts("");
flot ++;
int p = a[];
bool kg = false;
do{
if(a[] == )continue;
if(a[] == p){
if(kg)printf(" ");
}else{
if(p)puts("");
p = a[]; }
kg = true; for(int j = ; j < ; j++){
printf("%d", a[j]);
} }while(next_permutation(a, a + ));
printf("\n");
}
return ;
}

排列2(全排列next_permutation 注意格式)的更多相关文章

  1. 7.2.1 生成1~n的排列(全排列)【STL__next_permutation()_的应用】

    #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> ...

  2. 全排列next_permutation()用法和构造函数赋值

    全排列next_permutation()用法 在头文件aglorithm里 就是1~n数组的现在的字典序到最大的字典序的依次增加.(最多可以是n!种情况) int a[n]; do{ }while( ...

  3. 关于全排列 next_permutation() 函数的用法

    这是一个c++函数,包含在头文件<algorithm>里面,下面是基本格式. 1 int a[]; 2 do{ 3 4 }while(next_permutation(a,a+n)); 下 ...

  4. 全排列 next_permutation() 函数的使用

    看来看去还是这篇博客比较简洁明了 https://www.cnblogs.com/My-Sunshine/p/4985366.html 顺便给出牛客网的一道题,虽然这道题用dfs写出全排列也能做,题意 ...

  5. 排列组合函数next_permutation()

    next_permution(),按照字典序进行排列组合, 括号里的参数为类似sort里面的参数,用法相同 #include <bits/stdc++.h> using namespace ...

  6. HDOJ 1716 排列2(next_permutation函数)

    Problem Description Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数. Input 每组数据占一行,代表四张卡 ...

  7. 全排列 next_permutation 用法

    给一个正整数n,让你求它的全排列 先介绍一个函数,iota(a,a+n,1) 用法就是把a数组的第0位到第n-1位依次赋为1,2,.....n: 然后是next_permutation(a,a+4)函 ...

  8. 全排列 next_permutation() 函数的用法

    在头文件<algorithm>里面有如下代码: int a[]; do { } while(next_permutation(a,a+n)); 可产生1~n的全排列有如下代码: #incl ...

  9. 排列算法汇总(下一个排列,全排列,第K个排列)

    一.下一个排列 首先,STL提供了两个用来计算排列组合关系的算法,分别是next_permutation和prev_permutation. next_permutation(nums.begin() ...

随机推荐

  1. 1.php代码块

    一.登录 <form action="index.php?m=admin&c=index&a=login&dosubmit=1" method=&qu ...

  2. Maven打包生成源码包和Javadoc包

    https://blog.csdn.net/top_code/article/details/53586551 当我们开发了一个公共模块,将它deploy到Maven仓库时,最好同时提供源码包和Jav ...

  3. FileZilla等软件搭建ftp服务器

    一.常用的几款ftp服务器软件介绍 1.1 Server-U Serv-U是一种被广泛运用的FTP服务器端软件,支持3x/9x/ME/NT/2K/2000/xp等全Windows系列.可以设定多个FT ...

  4. 关于Unity中常用的数据结构和JSON处理(专题三)

    数据结构通俗来讲就是用某个对象去存储数据集合,比如要存储100个整数,要用什么样的数据类型能把它们存储好. Jason处理,服务器对接,配置文件的使用,Unity和Jason之间相互的转换. Arra ...

  5. e821. 设置JScrollPane滚动栏

    A scroll bar in a scroll pane can be set to appear only as needed, always appear, or never appear. B ...

  6. [ACM] POJ 1611 The Suspects (并查集,输出第i个人所在集合的总人数)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21586   Accepted: 10456 De ...

  7. Wrong codepoints for non-ASCII characters inserted in UTF-8 database using CLP

    Technote (troubleshooting) Problem(Abstract) During insert from the CLP there is no codepage convers ...

  8. scala实现相邻两个元素挑换位置的代码,哈哈

    import scala.math._ import breeze.plot._ import breeze.linalg._ import scala.collection.mutable.Arra ...

  9. php的MCRYPT_RIJNDAEL_256 和mcrypt_encrypt 用法

    <?php $key = "miyao";//密钥 $string="jiami";//需要加密的字符 $d = new d(); //加密 $crypt ...

  10. lnmp无法删除.user.ini文件的解决办法

    有一次使用命令lnmp vhost del删除虚拟主机后,需要使用ftp或者rm命令删除网站目录,但是却发现网站目录下有个文件.user.ini文件没有自动删除,出现提示rm: cannot remo ...