Description

You are to write a program that has to generate all possible words from a given set of letters.
Example: Given the word "abc", your program should - by
exploring all different combination of the three letters - output the
words "abc", "acb", "bac", "bca", "cab" and "cba".

In the word taken from the input file, some letters may
appear more than once. For a given word, your program should not produce
the same word more than once, and the words should be output in
alphabetically ascending order.

Input

The input consists of several words. The first line contains a number
giving the number of words to follow. Each following line contains one
word. A word consists of uppercase or lowercase letters from A to Z.
Uppercase and lowercase letters are to be considered different. The
length of each word is less than 13.

Output

For each word in the input, the output should contain all different
words that can be generated with the letters of the given word. The
words generated from the same input word should be output in
alphabetically ascending order. An upper case letter goes before the
corresponding lower case letter.

Sample Input

3
aAb
abc
acba

Sample Output

Aab
Aba
aAb
abA
bAa
baA
abc
acb
bac
bca
cab
cba
aabc
aacb
abac
abca
acab
acba
baac
baca
bcaa
caab
caba
cbaa

Hint

An upper case letter goes before the corresponding lower case letter.
So the right order of letters is 'A'<'a'<'B'<'b'<...<'Z'<'z'.
 
STL的全排列问题,写好排序方案,直接调用 next_permutation()函数便可!
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm> using namespace std; int n;
char str[15]; bool cmp(char a,char b)
{
if(tolower(a)==tolower(b))
return a<b;
else
return tolower(a)<tolower(b);
} int main()
{
scanf("%d",&T);
while( T-- )
{
scanf("%s",str);
sort(str,str+strlen(str),cmp);//自定义排序
do
{
cout << str << endl ;
}while(next_permutation(str,str+strlen(str),cmp));
} return 0;
}
 

ACM题目————Anagram的更多相关文章

  1. ACM题目————中缀表达式转后缀

    题目描述 我们熟悉的表达式如a+b.a+b*(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说)操作符在两个操作数中间:num1 operand num2.同理,后缀表达式就是操作符在两 ...

  2. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

  3. ACM题目推荐(刘汝佳书上出现的一些题目)[非原创]

    原地址:http://blog.csdn.net/hncqp/article/details/1758337 推荐一些题目,希望对参与ICPC竞赛的同学有所帮助. POJ上一些题目在http://16 ...

  4. 有一种acm题目叫做,奇葩!

    本文全然没有技术含量,纯粹是娱乐. 我事实上想写点东西.可是近期好像做计算几何做得太多了,一种想说说不出东西的感觉,唯有写一下一些奇葩的题目了. HDU3337:Guess the number pi ...

  5. ACM题目————STL练习之求次数

    题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个 ...

  6. ACM题目————zoj问题

    题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:20322 解决:3560 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. ...

  7. ACM题目————又见拦截导弹

    描述 大家对拦截导弹那个题目应该比较熟悉了,我再叙述一下题意:某国为了防御敌国的导弹袭击,新研制出来一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:它的第一发炮弹能够到达任意的高度,但是以后每一发炮 ...

  8. ACM题目————还是畅通工程

    Submit Status Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路 ...

  9. ACM题目————小A的计算器

    Description 以往的操作系统内部的数据表示都是二进制方式,小A新写了一个操作系统,系统内部的数据表示为26进制,其中0-25分别由a-z表示.  现在小A要在这个操作系统上实现一个计算器,这 ...

随机推荐

  1. 测试App运行状态

    示例代码: #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - ...

  2. linux 命令进阶

    1. ls –i -i, --inode            显示每个文件的inode 号 查看inode 可以用于 同一个classloader加载同名class时,是以先加载到的class为准, ...

  3. IntelliJ IDEA 常用设置讲解2

    IntelliJ IDEA 有很多人性化的设置我们必须单独拿出来讲解,也因为这些人性化的设置让我们这些 IntelliJ IDEA 死忠粉更加死心塌地使用它和分享它. 常用设置 如上图 Gif 所示, ...

  4. 通达信:显示K线图日期

    INFO_A:=STRCAT('INFO_A=', STRCAT(CON2STR(REF(MONTH, REF_BAR_A), 0), STRCAT('-', STRCAT(CON2STR(REF(D ...

  5. contesthunter CH Round #64 - MFOI杯水题欢乐赛day1 solve

    http://www.contesthunter.org/contest/CH Round %2364 - MFOI杯水题欢乐赛 day1/Solve Solve CH Round #64 - MFO ...

  6. 封装mysqli类

    类: <?phpheader('content-type:text/html;charset=utf-8');/*掌握满足单例模式的必要条件(1)私有的构造方法-为了防止在类外使用new关键字实 ...

  7. 配置文件App.config的使用以及Readonly与Const的对比

    以前我们学习的时候都把连接数据库的连接字符串写在一个类中,因为我们的数据库都在自己电脑上.如果更换数据库地址,需要更改这个类,然后重新编译才可以连接到数据库.现在我们需要将连接字符串当道一个文件中,然 ...

  8. paper 74:MATLAB图像处理_HSV与RGB颜色空间互转

    HSV空间:分别是H(色调)——S(饱和度)——V(亮度) 与HSI颜色空间类似:分别是H(色调)——S(饱和度)——I(强度) 注意: 强度和亮度差不多是一个概念. 饱和度代表的是渗入白光的数量级, ...

  9. 夺命雷公狗---微信开发56----微信js-sdk接口开发(3)所有接口功能

    按照上节课程里面的介绍,我们可以先将刚才在signatrue.php里获取到的信息填写进jssdk.htm模版文件里填写各个权限的参数 jssdk.htm代码如下: <!DOCTYPE html ...

  10. overfit & underfit

    原文:http://blog.csdn.net/yhdzw/article/details/22733317 过拟合:1)简单理解就是训练样本的得到的输出和期望输出基本一致,但是测试样本输出和测试样本 ...