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. Python生成8位随机密码

    #!/usr/bin/env python # -*- coding: utf- -*- import random import string #第一种方法 seed = "1234567 ...

  2. SQL循环添加表中的字段

    USE BookDiscuss                   DECLARE @num INT  DECLARE @numdiff INT  DECLARE @table  VARCHAR(50 ...

  3. JSP out乱码

    在form method="post" 写post 在接受页面jsp代码前面加request.setCharacterEncoding("UTF-8");

  4. RMQ求区间最值 nlog(n)

    转载于:http://blog.csdn.net/xuzengqiang/article/details/7350465 RMQ算法全称为(Range Minimum/Maximum Query)意思 ...

  5. ofbiz进击 第六节。 --OFBiz配置之[widget.properties] 配置属性的分析

    配置内容分析如下 # -- 定义上下文使用者 -- security.context =default # -- 定义密码限制长度最小值 -- password.length.min =5 # -- ...

  6. Excel 生成sql语句

    CONCATENATE 拼接字符串 IF 不能跟 CONCATENATE 连用,所以可以通过建立新列去完成更高的需求 新建一列 cw=CONCATENATE("insert into biC ...

  7. php 警告

    php.ini error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT error_log = /var/log/php-fpm/php ...

  8. paper 60 :转载关于视觉SCI期刊

    ChanLee_1整理的计算机视觉领域稍微容易中的期刊 模式识别,计算机视觉领域,期刊 (1)pattern recognition letters, 从投稿到发表,一年半时间 (2)Pattern  ...

  9. C# 把字符串类型日期转换为日期类型

    方法一:Convert.ToDateTime(string) string格式有要求,必须是yyyy-MM-dd hh:mm:ss ================================== ...

  10. linux中的一个看图的软件

    毕竟才是初入linux,很多工具,先要要求有个用着,之后再要求小巧强大好用. 看图软件,不喜欢kde或者是gnome这种庞大的桌面环境,也就不喜欢一些跟特定桌面环境沾边的软件(总觉得用软件必须要用特定 ...