题意:给你一条字符串,让你输出字符串中字符的全排列,输出的顺序要按它给的奇葩的字典序。

题解:要输出全排列,暴力dfs可以过,但要注意题目的字典序以及相同字符的情况。如果用next_permutation()处理可以简单很多;我是先将字典序"A a B b...Z z"的每个字母赋予一个值,即从1 2 3...52。然后将给的字符串全部转换成对应的数值后,用next_permutation()进行全排列(当然 题目给的字典序有一定规律,所以也可以直接给next_permutation()写个cmp函数直接处理字符串)。

 /**
* @author Wixson
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <map>
#include <set>
const int inf=0x3f3f3f3f;
const double PI=acos(-1.0);
const double EPS=1e-;
using namespace std;
typedef long long ll;
typedef pair<int,int> P; char str[];
char book[];
int a[];
void init()
{
for(int i=;i<;i++)
{
if(i%) book[i]='a'+i/;
else book[i]='A'+i/;
}
}
int main()
{
//freopen("input.txt","r",stdin);
init();
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%s",str);
n=strlen(str);
for(int i=;i<n;i++)
{
if(str[i]>='A'&&str[i]<='Z') a[i]=(str[i]-'A')*;
else a[i]=(str[i]-'a')*+;
}
//
sort(a,a+n);
do
{
for(int i=;i<n;i++) putchar(book[a[i]]);
putchar('\n'); }while(next_permutation(a,a+n));
}
return ;
}

poj 1256 Anagram—next_permutation的神奇应用的更多相关文章

  1. POJ 1256.Anagram

    2015-06-04 问题简述: 输出一串字符的全排列,顺序不同于一般的字母序,而是 A<a<B<b......<Z<z.所以应该重写一个比较函数. 原题链接:http: ...

  2. poj 1256 Anagram(dfs)

    题目链接:http://poj.org/problem?id=1256 思路分析:该题为含有重复元素的全排列问题:由于题目中字符长度较小,采用暴力法解决. 代码如下: #include <ios ...

  3. poj 2408 Anagram Groups(hash)

    id=2408" target="_blank" style="">题目链接:poj 2408 Anagram Groups 题目大意:给定若干 ...

  4. next_permutation,POJ(1256)

    题目链接:http://poj.org/problem?id=1256 解题报告: 1.sort函数是按照ASC11码排序,而这里是按照 'A'<'a'<'B'<'b'<... ...

  5. POJ 1256:Anagram

    Anagram Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18393 Accepted: 7484 Description ...

  6. poj 1256 按一定顺序输出全排列(next_permutation)

    Sample Input 3aAbabcacbaSample Output AabAbaaAbabAbAabaAabcacbbacbcacabcbaaabcaacbabacabcaacabacbaba ...

  7. 1256 Anagram

    题目链接: http://poj.org/problem?id=1256 题意: 根据自定义的字典序: 'A'<'a'<'B'<'b'<...<'Z'<'z' 和输 ...

  8. POJ 2408 - Anagram Groups - [字典树]

    题目链接:http://poj.org/problem?id=2408 World-renowned Prof. A. N. Agram's current research deals with l ...

  9. 【字母全排列】 poj 1256

    深搜   注意与STL模版的去重函数唯一的区别就是有去重. #include <iostream> #include <cstdio> #include <string. ...

随机推荐

  1. Flume特点

    Flume 特点 1.可靠性 当节点出现故障时,日志能够被传送到其他节点上而不会丢失. Flume提供了三种级别的可靠性保障,从强到弱依次分别为: (1)  end-to-end(收到数据agent首 ...

  2. HTML中的行级标签和块级标签 《转换》

    1.html中的块级标签 显示为“块”状,浏览器会在其前后显示折行.常用的块级元素包括: <p>, <ul>,<table>,<h1~h6>等. 2.h ...

  3. webstorm中配置过visualsvn,后面做更改要更换authentication realm的解决办法

    找这个找了好久,一直改不过来,终于找到了解决办法 首先,在提交代码时提示: 但是我的authentication realm已经时这个了,并且账号和密码也改了,所以要更改authentication ...

  4. 转 IDEA 解决代码提示功能消失

    转载路径是  https://blog.csdn.net/hmily_hui/article/details/78213037 原文地址:https://github.com/Damao/Intell ...

  5. 【译】x86程序员手册06 - 2.4指令格式

    2.4 Instruction Format 指令格式 The information encoded in an 80386 instruction includes a specification ...

  6. 一款批量linux管理工具batchshell

    BatchShell是什么? BatchShell是一款基于SSH2的批量文件传输及命令执行工具,它可以同时传输文件到多台远程服务器以及同时对多台远程服务器执行命令.BatchShell基于原生的sh ...

  7. 15、Scala隐式转换和隐式参数

    1.隐式转换 2.使用隐式转换加强现有类型 3.隐式转换函数的作用域与导入 4.隐式转换发生时机 5.隐式参数 1.隐式转换 要实现隐式转换,只要程序可见的范围内定义隐式转换函数即可.Scala会自动 ...

  8. CSS3设计炫目字体

    阴影 .text-shadow{ text-shadow:#FF0000 0 0 10px; color:white; font-size:60px } 描边 <style> .text- ...

  9. Quartz实战

    https://my.oschina.net/yinxiaoling/blog/542336?fromerr=s3ko7u33 Quartz实战 > 一.内存型(1) <bean name ...

  10. Resetting the SMC & PRAM

    Resetting the SMC & PRAM on portables with a battery you should not remove on your own 1. Shut d ...