【一只蒟蒻的刷题历程】 【HDU-1716】 排列2 (全排列)
发布日期:2021-05-04 19:24:01 浏览次数:22 分类:精选文章

本文共 974 字,大约阅读时间需要 3 分钟。

H - 排列2

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_permitation 进行全排列

ps:不能有0开头的
难点:格式 格式 格式!!!!!

不同组:每输出完一组空一行,最后0000不空行

同组不同行:记录千位数,不同才换行
同行:先输出第一个,然后以空格+值的形式输出,防止末尾有空格

#include 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int main() { int a,b,c,d,cnt=0; while(cin>>a>>b>>c>>d && (a||b||c||d)) { if(cnt) cout<
999) cout<
0 && v[0]!=0) cout<<" "; if(cn1>0 && ans>999) cout<
上一篇:UVa401 Palindromes【回文词】 简单模拟
下一篇:【一只蒟蒻的刷题历程】 【HDU-1027】 Ignatius and the Princess II (全排列)

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2025年03月31日 18时06分57秒