// 给你字符串 按字典序输出所有排列
// 要是每个字母都不同 可以直接dfs ^_^
// 用前面说的生成排列算法 也可以直接 stl next_permutation #include <iostream>
#include <string>
#include<sstream>
#include <cmath>
#include <map>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char s[];
int n;
void change(int l,int r)
{
while(l<r)
{
swap(s[l],s[r]);
l++;
r--;
}
}
bool permutation()
{
int i=n-;
while(i>&&s[i-]>=s[i]) i--;
if(!i) return false;
int k=i,j=n-;
for(;j>i;j--)
if(s[j]>s[i-]){
k=j;
break;
}
swap(s[i-],s[k]);
change(i,n-);
return true;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",s);
n=strlen(s);
sort(s,s+n);
do
{
printf("%s\n",s);
}while(permutation());
printf("\n");
}
return ;
}

UVA 10098 Generating Fast, Sorted Permutation的更多相关文章

  1. uva10098 Generating Fast, Sorted Permutation

    #include"iostream"#include"stdio.h"#include"string.h"#include"alg ...

  2. (组合数学3.1.1.2)UVA 10098 Generating Fast(使用字典序思想产生所有序列)

    /* * UVA_10098.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> # ...

  3. UVa 10098: Generating Fast

    这道题要求按字典序生成字符串的全排列,不可重复(但字符可以重复,且区分大小写). 基本思路是先对输入的字符串按字典序排序,然后从第一位开始递归,从所有输入的字符中选出一个填充,然后再选第二位..... ...

  4. UVA - 10098 - Generating Fast (枚举排列)

    思路:生成全排列,用next_permutation.注意生成之前先对那个字符数组排序. AC代码: #include <cstdio> #include <cstring> ...

  5. uva 10098 Generating Fast(全排列)

    还是用的两种方法,递归和STL,递归那个是含有反复元素的全排列,这道题我 没有尝试没有反复元素的排列,由于从题目上并没有发现一定是有反复元素的() 贴代码: <span style=" ...

  6. UVA 10098 用字典序思想生成所有排列组合

    题目: Generating permutation has always been an important problem in computer science. In this problem ...

  7. UVA 11925 - Generating Permutations

    题意: 给出一个1到n的排列,给出操作顺序,使升序排列能变为所给排列. 分析: 正常冒泡排序的想法.如果前两个数,前面的大于后面的,则换(特例是n,1不能换).否则,就用2的逆操作,把最后的数放前面. ...

  8. UVA - 11992:Fast Matrix Operations

    线段树,注意tag优先级 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cs ...

  9. UVa 11925 Generating Permutations (构造法)

    题意:给定一个序列,让你从一个升序列变成该序列,并且只有两种操作,操作1:交换前两个元素,操作2:把第一个元素移动到最后. 析:一开始的时候吧,不会,还是看的题解,首先是要逆序来做,这样可能好做一点, ...

随机推荐

  1. SDUT2241计算组合数C(n,m)(组合数)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2241 这个题的代码适应性也挺强,但这个题倒不适 ...

  2. C# 中的命名规则

    需要注意: C# 区分大小写 ,若有int a 和 int A ,则a, 和 A是不同的 普通字段,属相,方法,类的命名规则: C#中推荐使用  camelCasing ,和 PascalCasing ...

  3. struts2学习笔记(2)——简单的输入验证以及标签库的运用

    struts2自带了一些标签库,运用好这些标签库会减少开发周期. 1.struts2标签库是在哪定义的? struts2标签库定义在struts2-core-2.1.8.jar这个文件中,具体在这个j ...

  4. PHP输入流php://input [转]

    对于php://input介绍,PHP官方手册文档有一段话对它进行了很明确地概述. "php://input allows you to read raw POST data. It is ...

  5. VC程序查错之内存访问异常

    作者:langouster 先来看下面这张图,相信很多程序员都见过类似. ---------------------------test1.exe - 应用程序错误------------------ ...

  6. Qt出现警告 Unescaped backslashes are deprecated!解决办法

    Fixing Qt Warning: Unescaped backslashes are deprecated! From: http://www.openguru.com/2011/10/fixin ...

  7. 使用List,Dictionary加载数据库中的数据

    情景描述:数据库中有一张设备表,字段DWDM存放的是各个厂编号,字段ZNBH存放的是设备编号.其中DWDM跟ZNBH是一对多的关系.需要将数据库中的值加载到List<Dictionary< ...

  8. AndroidRichText 让Textview轻松的支持富文本(图像ImageSpan、点击效果等等类似QQ微信聊天)

    代码地址:https://github.com/Luction/AndroidRichText AndroidRichText帮助实现像QQ,微信一样的,一个TextView里既有文字又有表情又有图片 ...

  9. 使用Retrofit时出现 java.lang.IllegalArgumentException: URL query string "t={type}&p={page}&size={count}" must not have replace block. For dynamic query parameters use @Query.异常原因

    /** * Created by leo on 16/4/30. */ public interface GanchaiService { @GET("digest?t={type}& ...

  10. spring cloud config 入门

    简介 Spring cloud config 分为两部分 server client config-server 配置服务端,服务管理配置信息 config-client 客户端,客户端调用serve ...