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

贴代码:

<span style="font-family:Courier New;font-size:18px;">#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int cmp(const void *a,const void *b)
{
return *(char *)a - *(char *)b;
}
int main()
{
int T;
char a[15];
scanf("%d",&T);
while(T--)
{
scanf("%s",a);
int len = strlen(a);
qsort(a,len,sizeof(a[0]),cmp);
puts(a);
while(next_permutation(a,a+len))
{
puts(a);
}
puts("");
}
return 0;
} </span>

递归:

<span style="font-family:Courier New;font-size:18px;">#include<stdio.h>
#include<string.h>
#include<stdlib.h> int cmp(const void *a,const void *b)
{
return *(char *)a - *(char *)b;
}
void solve(int len,char *a,char *b,int cur)
{
int i,j;
if(cur == len)
{
puts(b);
return ;
}
else
{
for(i=0; i<len; i++)
{
if(!i||(a[i] != a[i-1]))
{
int ans1 = 0, ans2 = 0;
for(j=0; j<len; j++) if(a[i] == a[j]) ans1++;
for(j=0; j<cur; j++) if(b[j]==a[i]) ans2++;
if(ans2 < ans1)
{
b[cur] = a[i];
solve(len, a, b, cur+1);
}
}
}
}
return ;
}
int main()
{
int T;
char a[15];
char b[15];
scanf("%d",&T);
while(T--)
{
memset(a,'\0',sizeof(a));
memset(b,'\0',sizeof(b));
scanf("%s",a);
int len = strlen(a);
qsort(a,len,sizeof(a[0]),cmp);
solve(len,a,b,0);
puts("");
}
return 0;
} </span>

uva 10098 Generating Fast(全排列)的更多相关文章

  1. UVa 10098: Generating Fast

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

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

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

  3. UVA 10098 Generating Fast, Sorted Permutation

    // 给你字符串 按字典序输出所有排列// 要是每个字母都不同 可以直接dfs ^_^// 用前面说的生成排列算法 也可以直接 stl next_permutation #include <io ...

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

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

  5. generating permunation——全排列(算法汇总)

    本文一共提供了4种全排列的方法,包括递归非字典序版本.递归字典序版本.标准库版本和BFS字典序版本,当然BFS非字典序实现相对于BFS字典序版本更加简洁,稍加修改即可. 说明:递归版本基于网上现有代码 ...

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

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

  7. uva10098 Generating Fast, Sorted Permutation

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

  8. UVA 11925 - Generating Permutations

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

  9. UVA - 11992:Fast Matrix Operations

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

随机推荐

  1. PHP设置30秒内对页面的访问次数

    <?php //Calculate 60 days in the future //seconds * minutes * hours * days + current time $intime ...

  2. mysql异常Lock wait timeout exceeded; try restarting transaction

    mysql中使用update语句更新数据报错: Lock wait timeout exceeded; try restarting transaction. 这是由于你要更新的表的锁在其它线程手里. ...

  3. vim基础学习之自动补全功能

    本章我们学习自动补全功能1.自动补全优先从当前的编辑区获得补全列表例如:我们写下如下内容 aaaaa aabbb aaab 当我们再次输入aa,然后我们按下Tab的时候,会弹出一个包含 aaaaa a ...

  4. vim 解决tags递归查询问题

    今天在vim下配置了两个插件,分别是exuberant-ctags 跟cscope.这两个插件主要是用来实现类.方法查询跟跳转.至于它们如何安装跟使用,网上教程一大堆,我也是按着别的大神教程一步步来的 ...

  5. 71.用express框架,出现 express.Router is not a function

    Express版本太久

  6. webservices 服务器未能识别 HTTP 头 SOAPAction 的值:.

    转自:https://blog.csdn.net/dxfasr/article/details/25029063 在用java发送给webservice服务器的时候报如下错误: AxisFault f ...

  7. 7.Emmet----HTML以及CSS的缩写请查看

  8. Java中Webservice调用.NET天气接口生成客户端异常

    学习webservice时候有个例子调用公网的天气预报接口实现查询天气的功能.然而在使用命令编译客户端代码的时候出错了.大概看了一下网上说是需要将将文件中所有出现的 < s:element re ...

  9. python爬虫之『入门基础』

    HTTP请求 1.首先需要了解一下http请求,当用户在地址栏中输入网址,发送网络请求的过程是什么? 可以参考我之前学习的时候转载的一篇文章一次完整的HTTP事务过程–超详细 2.还需要了解一下htt ...

  10. Android eclipse 提示java代码 快捷键

    1.提示java代码能够用ALT+/ 键就能够了(前提是你要把你须要的类或方法的首字母打出来).我添加的部分:仅仅要输入sysout,然后alt+/键就能够输出System.out.prinln(), ...